clear, clc, clf
x=[0 1 3 4]';
y=[1 8 11 20]';

%a
A=[x ones(4,1)];
kx=A\y
plot(x,y,'*')
hold on
xlin=[0 4];
ylin=[kx(1)*xlin+kx(2)];
plot(xlin,ylin)
residual=A*kx-y

%b 
A=[ones(4,1)];
kx2=(A'*A)\(A'*y)
ylin=ones(size(xlin))*kx2;
plot(xlin,ylin)
residual2=A*kx2-y

%c
A=[x];
kx3=A\y
ylin=xlin*kx3;
plot(xlin,ylin)
residual3=A*kx3-y
