% The Singular Value Decomposition (SVD):
% 
% For any rectangular matrix A, with real or complex entries, 
% there is a rectangular diagonal matrix  Sigma
% containing only nonnegative real values (called the singular values of A),
% and square unitary matrices U and V
% so that A can be decomposed as the product:
%
%          A = U * Sigma * V'
%
% (in Matlab V' is the Hermitian transpose, i.e., the conjugated transpose of V)
%

n = 3

A = rand(n,n)
Sigma = svd(A)

% We can also get the U and V matrices of the SVD as follows:

[U,Sigma,V] = svd(A);

SingularValues = Sigma

% U is unitary.
U
ShouldBeOne = det(U)
ShouldBeIdentity = U * U'


% V is unitary also.
V
AlsoShouldBeOne = det(V)
AlsoShouldBeIdentity = V * V'


% We can validate that the Singular Value Decomposition really holds for A:

ShouldBeZero = A - U * Sigma * V'

AlsoShouldBeZero = Sigma - U' * A * V 

