Change order of eigenvalues and correspoding eigenvector

469 Views Asked by At

I'm struggling with some bugs in my program and try to find the mistakes.

The situation is as follows:

I have a covariance Matrix on which I perform a principal component decomposition into a Eigenvector- and Eigenvalues-Matrix (diagonal).

If I multiply the matrices which I received in the following manner:

Eigenvector * Eigenvalues * Eigenvector (transposed)

I should receive the covariance matrix back. And this is also the case. But the eigenvalues are not in decreasing order, so I wrote a loop which sorts the values in the diagonal matrix and also switches the corresponding positions in the Eigenvector Matrix. Afterwards if I multiply the matrices again, I get almost the covariance matrix, but with a deviation.

Now my question would be, have I missed something or is the operation to switch the order of the eigenvalues and respective eigenvectors not possible?

Thank you in advance!