Computing singular value decomposition via Matlab script

244 Views Asked by At

Let $A = \begin{pmatrix} 10&20\\ -3 & 4 \end{pmatrix}$.

I want to compute the svd decomposition $A=USV'$ via matlab, but I do not want to use the function svd.

First of all, I have to compute the vector $U$ and $V$, so:

A=[10 20;-3 4]; [U,D]=eig(A*A'); [V,D]=eig(A'*A);

The problem is that my matrix $D$ has the property $D(1,1)<D(2,2)$. In order to find my matrix $S$ I have to type:

S=sqrt(diag([D(2,2) D(1,1)]))

But, since I reverted the order of the elements from the diagonal matrix, I also have to swap the columns of $U$ and $V$ in order to maintain the correspondence beetween the eigevectors and the eigenvalues previously computed:

V(:,[1 2])=V(:,[2 1]); U(:,[1 2])=U(:,[2 1]);

And the result is:

U*S*V'

But the result (shown below) its not equal to $A$!

$\begin{pmatrix} -10&-20\\ +3 & -4 \end{pmatrix}$.

EDIT: Computing the SVD decomposition through the matlab function svd

[U1,S1,V1]=svd(A)

we can note some differences:

From my computation $U = \begin{pmatrix} -0.9946 & 0.1036 \\ -0.1036 & -0.9946 \end{pmatrix}$ and from matlab: $U1 = \begin{pmatrix} -0.9946 & -0.1036 \\ -0.1036 & 0.9946 \end{pmatrix}$ we see that the difference its in the second eigenvector of $AA'$ since they are multiples of $-1$ to each other.

A similar difference happens beetween $V$ and $V1$, in this case, however, the first eigenvector of $A'A$ are multiple of $-1$ to each other.

I thought that $U$ and $V$ should be just an orthogonal matrix whose columns are constitued by, respectively, eigenvectors of $AA'$ and $A'A$. And the matrices $U$ and $V$ that I computed satisfies these conditions, so why am I having this wrong result?

Sorry for the long post..