%**** Examples - Chapter 02 ****;

%**** Example 2.9 Permutations *(ref.: ./solved_examples/ch02_matrix_trans.m);
%%%% Demonstrate the effects of permutations.
% Define a vector b of 3 components with values: 1 2 3.
% Construct a permutation matrix P that interchanges original element order 1, 2, 3 in 2, 3, 1.
% Use left multiplication on b and comment results.
% Calculate inverse and transpose of P, comment results.
% Construct a 3x3 matrix A with values of elements in the first row: 
% 1 2 3, second row: 2 5 7 and third row: 0 1 3
% Check if A is nonsingular.
% If so solve the system Ax=b using Matlab function, if not find another nonsingular matrix.
% Pre-multiply the system by P and solve it again. Comment results.
% Post-multiply A by P and solve the system again. Comment results.
% Restore the original solution.


%**** Example 2.10 Diagonal scaling *(ref.: ./solved_examples/ch02_matrix_trans.m);
%%%% Demonstrate the effects of diagonal scaling.
% Define a vector b with 3 random components.
% Construct a diagonal 3x3 matrix D with diagonal elements equal to 4.
% Use left multiplication on b and comment results.
% Calculate inverse and transpose of D, comment results.
% Construct a 3x3 matrix A with random elements.
% Check if A is nonsingular.
% If so solve the system Ax=b using Matlab function, if not find another nonsingular matrix.
% Pre-multiply the system by D and solve it again. Comment results.
% Post-multiply A by D and solve the system again. Comment results.
% Restore the original solution. 


%**** Example 2.11 Triangular linear system *(ref.: ./solved_examples/ch02_matrix_trans.m);
%%%% Demonstrate how to find the solution of an upper triangular system.
% Define a nonsingular upper triangular system Ax=b of dimension 3x3.
% Construct the solution in a simple way, by components.
% Confirm your results by Matlab function.


%**** Example 2.13 Gaussian elimination *(ref.: ./solved_examples/ch02_matrix_trans.m);
%%%% Demonstrate how the Gaussian elimination with no pivoting works.
% Use the system from Example 2.9 of dimension 3.
% Construct consecutive Mi matrices and annihilate corresponding column elements of A.
% Store matrix M in a separate space. 
% Pre-multiply matrix A by M. Comment obtained results.
% Find inverse of M. Comment results.
% Show that L*U = A.
% Solve the system using the matrix M and Matlab function. Describe the method.
% Solve the system again, using matrices L and U and Matlab functions. Describe the method.
% Compare your results with Matlab solution.


%**** Example 2.16 Gaussian elimination with partial pivoting *(ref.: ./solved_examples/ch02_matrix_trans.m);
%%%% Partial pivoting improves numerical stability.
% Use the same system as in the previous example.
% Construct L and U factors using partial pivoting.
% Show permutation matrix.
% Show that P*A = L*U
% Find the solution and compare your results by results of previous example.


%**** COMPUTER PROBLEM 2.xx *(ref.: ./solved_examples/ch02_ludecomposition.m);
%%%Usually, the Gaussian elimination is implemented as a triple loop, followed by
% forward and backward substitutions.
% Implement a program code for the solution of a system of n linear equations with no pivoting.
% The matrix M is not needed explicitly. The L and U matrices are stored 
% in the place of the original matrix A.
% Backward and forward substitutions are used then to obtain the solution x.
% Implement the solution of a system with n equations as described above.
% Test your program for different random systems and compare your results with Matlab solutions.
