t = [0 1 3 4]';
y = [1,8,11,20]';
A = [ones(4,1) t];
x = A\y
r1 = abs(y-A*x)'
% x = inv(A'*A)*A'*y
figure(1)
plot(t,y,'cs')
hold on
tplot = linspace(0,4);
plot(tplot,x(1) + x(2)*tplot)

A = ones(4,1);
x = A\y
r2 = abs(y-A*x)'
plot(tplot,x*ones(100,1),'r--')

A = t;
x = A\y;
r3 = abs(y-A*x)'
plot(tplot,x*tplot,'m:')



A = [ones(4,1) t t.^2 t.^3];
x = A\y
r4 = abs(y-A*x)'
% x = inv(A'*A)*A'*y
plot(tplot,x(1) + x(2)*tplot+...
    x(3)*tplot.^2+x(4)*tplot.^3)

hold off


