function [tab]=vardec(A,C,K,V,N)
%function [tab]=vardec(A,C,K,V,N)
%  Calculates the variance decomposition of the k-step
%  ahead prediction errors for z(t) in the innovations system
%
%      x(t+1) = A * x(t) + K * u(t)
%
%        z(t) = C * x(t) + u(t)
%
%       E u(t)*u(t)' = V
%
%  The u's are the innovations in the z's.  VARDEC prepares a table
%  of diagonal elements of the covariance matrix of the
%  k-step ahead prediction errors, k=1,2, ... N.
%  The output is stored in the matrix tab which has N
%  rows and m=max(size(V)) columns.  The (k,h) element of tab gives
%  the variance of the k-step ahead prediction error for the hth variable
%  in z(t).
%
%  SEE ALSO: VARDECI
  m=max(size(V));
tab=zeros(N,m);
v1=V;
tab(1,:)=diag(v1)';
v2=V+C*K*V*K'*C';
tab(2,:)=diag(v2)';
v0=v2;
for i=3:N
AI=A^(i-1);
vv=v0+C*AI*K*V*K'*AI'*C';
tab(i,:)=diag(vv)';
v0=vv;
end
tab;
