//exec('kf.3.ex')
//initialize state statistics (mean and err. variance)
   m0=[10 10]';
   p0=[2 0;0 2];
//create system
   f=[1.1 .1;0 .8];
   g=[1 0;0 1];
   h=[1 0;0 1];
//noise statistics
   q=[.03 .01;.01 .03];
   r=2*eye(2);
//initialize system process
   rand('seed',2),
   rand('normal'),
   p0c=chol(p0);
   x0=m0+p0c'*rand(ones(m0));
   yt=[];
//initialize kalman filter
   xke0=m0;
   pk0=p0;
//initialize err. variance
   ecv=[pk0(1,1) pk0(2,2)]';
//loop
   n=10;
   for k=1:n,
//generate the state and observation at time k (i.e. x(k+1) and y(k))
      [x1,y]=system(x0,f,g,h,q,r);
      x0=x1;
//track the state with the standard kalman filter
      [xke1,pk1,xd,pd]=kalm(y,xke0,pk0,f,g,h,q,r);
      ecv=[ecv [pk1(1,1) pk1(2,2)]'];
      xke0=xke1;
      pk0=pk1;
//end loop
   end,
//display square root of err. covariance
   sqrt(ecv)'
