function theta = SequentialLSExample1 (Nmax, sigma2) a = -6; b = -0.6; c = 0.004; for n=1:Nmax x(n) = a + b*n + c*n.^2 + sqrt(sigma2)*randn(); H = [ones(n,1) (1:n)' (1:n)'.^2]; figure(1);clf;hold on; plot(x,'*-'); if n>=3 theta = inv(H'*H)*H'*x' xfit = theta(1) + theta(2)*(1:Nmax) + theta(3)*(1:Nmax).^2; plot(xfit,'ro-'); end; axis([0 Nmax -100 100]); pause(0.1); end;