%**** Examples from Chapter 04 ****

%**** Example 4.3 Characteristic Polynomial *(ref.: ./solved_examples/ch04_examples.m);
%%%% calculate characteristic polynomial for a matrix
%A=[3 1; 1 3]	% symmetric matrix
% Use Matlab functions poly(A)  to determine coefficients of characteristic polynomial
% and roots(p) to determine eigenvalues.
% Repeat the same procedure on the matrix A=[1 0 2; 0 2 1; 2 1 1]. What is the companion 
% matrix. Find its eigenvalues and egenvectors by Matlab function eig(C).


%**** Example 4.7 Eigenvalue Sensitivity *(ref.: ./solved_examples/ch04_examples.m);
%%%% demonstrate the eigenvalue sensitivity for the matrix 
%A=[-149 -50 -154; 537 180 546; -27 -9 -25]. Calculate eigevalues and eigenvectors using 
%Matlab functions. 
%Change slightly A(2,2) to 179.999 find the eigenvalues again.
%Comment and explain results.


%**** Example 4.14 Reyleigh Quotient iteration*(ref.: ./solved_examples/ch04_examples.m);
%%%% For the matrix A=[3 1; 1 3], implement the iterative algorithm and calculate 
% the maximal eigenvalue on 4 decimal digits. What is the corresponding eigenvector?
% Check your results using Matlab functions. What is the number of iterations needed?


%**** Example 4.15 QR Iteration *(ref.: ./solved_examples/ch04_examples.m);
%%%% reduces the matrix A into triangular or diagonal form by QR iteration.
% Find the approximate number of iterations that provide 4 decimal digits accuracy.
%A=[2.9766 0.3945 0.4198 1.1159;...
%      0.3945 2.7328 -0.3097 0.1129;...
%      0.4198 -0.3097 2.5675 0.6079;...
%      1.1159 0.1129 0.6079 1.7231;]	% symmetric matrix


%'**** Example 4.19 Jacobi Method *(ref.: ./solved_examples/ch04_examples.m);
%%%% reduce symmetric matrix A to a near diagonal matrix using Jacobi rotations.
%A=[1 0 2; 0 2 1; 2 1 1];	Implement an algorithm using MAtlab solvers for the 
%quadratic equation:
%% To annihilate symmetrically  placed entries (1,3) and (3,1) use plane rotation
% t= sym('t')
% p=1+t*(A(1,1)-A(3,3))/A(3,1) - t^2
% q=solve(p); roots of the quadratic equation
% take smaller absolute value of roots and restore c and s
% Generate plane rotation J and implement Jacobi iteration. Proceed for 3 next 
% steps.

%**** Computer experiment *(simmilar as in ref.: ./solved_examples/ch04_power_met.m);
% Plot origin (0,0) and 360 vectors from unit circle separated by 1 degree.
% Find and plot all transformed vectors after premultiplication by A.
% Use A=[0.7 1; 0.1 -1.2] 
% Repeat above transformation in a loop for 5 times.
% Interpret your results (readout the approximate eigenvalue and corresponding eigenvector)
% and confirm your results by Matlab.
