% m8_leastsquares.m - a little least-squares t = 2*pi*(1:30)'/30 A = [ cos(0*t) sin(t) cos(t) sin(2*t) cos(2*t) ] A'*A plot(A) plot(t,A) b = [ linspace(0,3,8) linspace(3,2,7) ... linspace(2,6,10) linspace(5,0,5) ]' plot(t,b,'ok'), grid on x = A\b hold on, plot(t,A*x,'r') b = b + randn(30,1) hold off, plot(t,b,'ok'), grid on x = A\b hold on, plot(t,A*x,'r') % (and just for fun, after clicking on the red curve...) set(gco,'linewidth',20)