% Example2_27.m
% Program sequentiala.m for Example 2.27, Sequential linear estimation for m=1.
clear all; format short g
n=3; p=2; mu=zeros(p,1); %mu is the prior parameter estimate vector
sigma=1; sig=sigma*ones(n,1); Pz=1.0e+5; X=[4 3; 1 2; 10 1]; y=[11 4 25]'; b=mu;
P0=Pz*eye(p,p); P=P0; B=mu';	%P0 is V sub(beta)
for ii=1:n;			%SEQUENTIAL
    A=P*X(ii,:)';	%eq. (2.9.8a)	%SEQUENTIAL
    Delta=sig(ii)^2+X(ii,:)*A;	%eq. (2.9.8)	%SEQUENTIAL
    K=A/Delta;	%eq. (2.9.8c)	%SEQUENTIAL
    e=y(ii)-X(ii,:)*b;	%eq. (2.9.8d)	%SEQUENTIAL
    b=b+K*e;	%eq. (2.9.8e)	%SEQUENTIAL
    P=P-K*A';	%eq. (2.9.8f)	%SEQUENTIAL
    B=[B; b'];
    if ii==1
        PP=[P(1,1) P(1,2) P(2,2)];
    else
        PP=[PP; P(1,1) P(1,2) P(2,2)];
    end
end
disp(' sequential b(1) b(2)'), B
disp(' sequential P(1,1) P(1,2) P(2,2)'), PP
