function YP = forecast(model,data,K, Init)
samples
[N, ny] = size(data);
Mss = idss(model);
ord = size(pvget(Mss,'A'),1);
if ord>N
error('Forecast:TooFewSamples','The data should contain at least %d
samples.',ord)
end
if nargin<4, Init = 'e'; end
yp = zeros(K,ny);
mp = getPredictor(Mss);
[Ap,Bp,Cp] = ssdata(mp);
if Init=='z'
xt = ltitr(Ap, Bp, data.y);
x0 = xt(end,:);
else
[A1,B1,C1,D1,K1] = ssdata(Mss);
x00 =
x0est(data.y,A1,B1,C1,D1,K1,size(C1,1),size(B1,2),250e3,eye(size(C1,1)));
x0 = ltitr(Ap,Bp,data.y,x00); x0 = x0(end,:);
end
u = [data.y(end,:); zeros(1,ny)];
for ct = 1:K
xt = ltitr(Ap, Bp, u, x0);
x0 = xt(end,:);
yp(ct,:) = (Cp*x0.').';
u = [yp(ct,:); zeros(1,ny)];
end
YP = data; YP.y = yp; YP.u = []; YP.Name = '';
YP.UserData = []; YP.Notes = '';
YP.Tstart = data.Ts*(N+1);
function mp = getPredictor(sysd)
[A,B,C,D,K] = ssdata(sysd);
Ts = sysd.Ts;
Ny = size(D,1);
mp = idss(A-K*C, [K B-K*D], C, [zeros(Ny), D], zeros(size(A,1),Ny), 'Ts',
Ts);
mp.InputDelay = [zeros(Ny,1); sysd.InputDelay];
Best Answer