%**** Examples - Chapter 03 ****;

% **** Example 3.2 Normal Equations Method *(ref.: ./solved_examples/ch03_examples.m);
%%%% Linear lest square fitting by quadratic polynomial to points (ti,yi)
% Tese measured values y = {1.0, 0.5, 0.0, 0.5, 2.0} have been obtained by
% at five equidistant data points t = {-1.0, -0.5, 0.0, 0.5, 1.0}.
% Fit these measurements by a quadratic polynomial.
% Print the coresponding Vandermonde matrix
% Solve this problem using least squares and normal equations.
% Solve the resulting system by the fastest method availabe in Matlab. 
% Describe and justify your selection.
% Plot data points and fitting curve on the same graph.
         
         
%**** Example 3.8 Householder QR Factorization *(ref.: ./solved_examples/ch03_examples.m);
%%%% Take matrix A and right-hand side vector b from the previous example.
% Construct the Householder matrices for each column and anihilate subdiagonal elements
% of A using step-by-step method, as in example 3.8. 
% The Householder transformation matrix can be obtained by H=H_n*H_n-1...H_2*H_1.
% Show that H*A = R, which is an upper triangular matrix.
% Transform the right-hand-side by H*b.
% Show that the norm is not changed after the Householder transformation.
% Solve the least square problem Ax~=b, as H*A*x = R*x = H*b = [c1,c2]'.
% What is the solution and how large is the minimum residual norm?
% Comment the expected conditioning of the obtained sulution.
 

%**** Example 3.10 Givens QR Factorization *(ref.: ./solved_examples/ch03_examples.m);
%%%%% Take matrix A and right-hand side vector b from the previous example.
% Construct the consecutive Givens rotations to annihilate sub-diagonal elements
% using step-by-step method, as in example 3.10. Start with the annihilation of element (5,1).
% Accumulate the complete Givens rotation matrix by G=G_n*G_n-1...G_2*G_1.
% Show that G*A = R, which is an upper triangular matrix.
% Transform the right-hand-side by G*b.
% Show that the norm of A is the same as the norm of R.
% Solve the least square problem by Matlab function.
% Compare R and b after pre-multiplication by Givens rotation matrix G.
% Show that G is orthogonal and confirm that A = G'R = Q*R.
% Comment results.


%**** Example 3.11 Modified Gram-Schmidt QR Factorization *(ref.: ./solved_examples/ch03_examples.m);
%%%%% Take matrix A and right-hand side vector b from the previous example.
% Construct the consecutive Gram-Schmidt matrices to orthogonalize the 
% first column against the subsequent columns. Proceed with the orthogonalization
% process of the second column against subsequent columns and so on as in example 3.11.
% Accumulate the complete Gram-Schmidt matrix GS and print the matrix R.
% Show that GS*R=A = Q*R, and that R*x = Q'*b.
% Solve that system and comment results.


%**** Implement modified Grahm-Schmidt orthogonalization *(ref.: notes, slide 45);
% by a program code segment as in the Algorithm 3.3.
% Estimate the number of floating point operations.
