load polynomial_x_regression.mat

L = -y;
P = diag(p);
A = [];

for i = 0 : 22

  i
  A = [x.^i A];
  % A = vander(x,i);
  X = -inv(A'*P*A)*(A'*P*L);
  V = A * X + L; 
  sumvpv = V'*P*V
  sigma  = sqrt( V'*P*V / ( size(A)(1)-size(A)(2)) )
  disp('') 
end

hold on
plot (x,y,'*');
plot(x,polyval(X,x),"*")
hold off

pause

