function [Uhat, Shat, Vhat] = mysvd(A)
%MYSVD - simplified implementation of SVD decomposition of a matrix
    B = A'*A;
    [V, D] = eig(B);
    % sort eigenvalues and eigenvectors
    [di, I] = sort(diag(D), 'descend');
    V = V(:, I);
    % 
    r = nnz(di);
    Vhat = V(:,1:r);
    di = sqrt(di(1:r));
    Shat = diag(di);
    Uhat = A*Vhat ./ di';
end
