# Why sometimes eigenvectors matrix cannot transform to initial matrix?

As we know, $$H=U^{-1}\Lambda U$$ where $$\Lambda$$ is the diagonal matrix and $$H$$ is the original matrix, $$U$$ is the eigenvector matrix. Also, we can restore the original matrix via: $$\Lambda=UHU^{-1}$$ However, I find such relation sometimes right in Mathematica and sometimes failure:

a = ( {
{2, -1, 0, 0},
{-1, 1, -1, 0},
{0, -1, -1, -1},
{0, 0, -1, -2}
} );
Da = N[DiagonalMatrix[Eigenvalues[a]]];
Sa = N[Eigenvectors[a]] // Transpose;
Sa.Da.Inverse[Sa] // MatrixForm


The result breaks this relation, i.e. different from the original matrix:

But, if I change another original matrix:

a = ( {
{1, -1, 0, 0},
{-1, 1, -1, 0},
{0, -1, 1, -1},
{0, 0, -1, -1}
} );
Da = N[DiagonalMatrix[Eigenvalues[a]]]
Sa = N[Eigenvectors[a]] // Transpose;
Sa.Da.Inverse[Sa] // MatrixForm


The result follow the relation above.

I am confused of such problem.

• I just pasted the first block of code into a notebook and I got the exact same matrix a back. In addition: not every matrix can be diagonalized this way, so you can't expect this to work for every matrix. en.wikipedia.org/wiki/Eigendecomposition_of_a_matrix – Sjoerd Smit Aug 6 at 8:03
• @SjoerdSmit Thanks for your comments! I change another computer and still obtain the "wrong" result, it seems strange. I will check whether it is the exception as you said. – Merlin Zhang Aug 6 at 8:17

Works fine for me:

a = {{1, -1, 0, 0}, {-1, 1, -1, 0}, {0, -1, 1, -1}, {0, 0, -1, -1}};

{Da, Sa} = Eigensystem[a];

Inverse[Transpose[Sa]].a.Transpose[Sa] == DiagonalMatrix[Da] // FullSimplify
(*    True    *)

Transpose[Sa].DiagonalMatrix[Da].Inverse[Transpose[Sa]] == a // FullSimplify
(*    True    *)

• Thanks for your answer! By comparing with your code, I find the key problem is that we must use "Eigensystem", rather than use "Eigenvalues" and "Eigenvectors" respectively. – Merlin Zhang Aug 6 at 9:02
• @Merlin, a more fundamental error that you made is that you did not transpose the result of Eigenvectors[]. – J. M.'s discontentment Aug 6 at 13:35