%computes singular value decomposition of a square nonsingular matrix
%A = USV^T where U,V are orthogonal and S is diagonal with nonzero entries = singular values

A = (1/sqrt(2))*[1,1;-2,2];

[Q,D] = eig(transpose(A)*A);

U = inv(transpose(A))*Q*sqrt(D);
S = sqrt(D);     %S = Sigma = diagonal matrix of singular values
V = Q;

disp('SVD is...')
U
S
V

