%% Homework 14: The Singular Value Decomposition
%% Due Monday, 5/2/2022, before 5pm. Submit a PDF of your work on Gradescope.
% In this study guide we will use the Singular Value Decomposition to construct a low-rank approximation of the following matrix.


A = [0.8147    0.0975    0.9280
     0.9058    0.2785    1.2814
     0.1270    0.5469    0.7696
     0.9134    0.9575    1.9194
     0.6324    0.9649    1.6773];

% Use the size function to check the dimensions of the matrix A.

% insert your code here

% Predict the dimensions of all three matrices in the SVD of A.
%     Dimensions of \mathbf{U}
% :
%     Dimensions of \mathbf{\Sigma}:
%     Dimensions of \mathbf{V}:
% Use the function svd to find the SVD of A. Call your matrices U, S, and V for \mathbf{U}, \mathbf{\Sigma}, and \mathbf{V}.

% insert your code here

% Verify that the product of your SVD matrices is the original matrix. In Matlab the apostrophe ' symbol transposes a matrix.

% insert your code here
 

% Look at the singular values of A. Let's drop the smallest singular value and see how much it affects the original matrix.
% First, make a copy of the S matrix called S2.

% insert your code here

% Now replace the smallest singular value in S2 with a zero.

% insert your code here 

% Construct the matrix A2 using the matrices U, S2, and V. Compare this matrix to the original matrix A.

% insert your code here

% Since the third singular value is small, dropping it has little effect on the matrix. There is not much information stored in the third singular vectors.
% Repeat this process by deleting either the second or first singular values.

% dropping the 2nd singular value

% dropping the 1st singular value

% Note how the larger the singular value, the larger the effect on the product of the SVD matrices.