% SAMPLE code for problem 8.1.5
% you need to form the matrices and find the coefficients for the approximation

% data points abscissa and ordinates
x = [4, 4.2, 4.5, 4.7, 5.1 5.5, 5.9, 6.3, 6.8, 7.1]';
y = [102.56, 113.18, 130.11, 142.05, 167.53, 195.14, 224.87, 256.73,299.50, 326.72]';

% best approximation first degree 
A = [ ones(size(x)), x];
c1=(A'*A)\(A'*y);
fprintf('Best approximation is %g + %g x\n',c1);
fprintf('error ||b-A*x||_2^2 for degree 1 approx = %g\n',norm(A*c1-y)^2);

% best approximation second degree 
A = ....
c2 = ....
fprintf('Best approximation is %g + %g x + %g x^2\n',c2);
fprintf('error ||b-A*x||_2^2 for degree 2 approx = %g\n',norm(A*c2-y)^2);

% best approximation third degree 
A = ....
c3 = ....
fprintf('Best approximation is %g + %g x + %g x^2 + %g x^3\n',c3);
fprintf('error ||b-A*x||_2^2 for degree 2 approx = %g\n',norm(A*c3-y)^2);

