# Can Eigenvalues[] and Eigenvectors[] be assumed to return the same ordering?

If I do back to back calls of Eigenvalues[] and Eigenvectors[] can these be assumed to order the values and vectors the same, or is each independent?

Related to this is a curiosity about the performance of a pair of calls like this. Are Mathematica optimizations done at an expression level, or if a result from one could help another later (or previous) calculation, is it able to reorder internally and/or make use of previous calculations?

• I would say it's vastly preferable to just use {vals, vecs} = Eigensystem[mat] if you in fact need both. – J. M. will be back soon Feb 16 '12 at 1:43

If you need to be sure that the order is correct, there is a function Eigensystem that returns a list of both the eigenvalues and -vectors, which is in the right order.

{eValues, eVectors} = Eigensystem[{{2, 0}, {0, 1}}];
eValues
eVectors

{2, 1}
{{1, 0}, {0, 1}}


It's probably worth using just for the slight off-chance that Eigenvalues and Eigenvectors do not yield the same order (not sure about whether this may or may not happen), which will be really painful to debug.

• Thanks for also showing the (perl-like) syntax fragment that gives names to the parts of the list, right in the assignment. I didn't know that was allowed and is helpful. – Peeter Joot Feb 16 '12 at 14:23

Yes. The easy way to check this is to do

M == Total@MapThread[#1 KroneckerProduct[#2,#2],
{Eigenvalues[M], Eigenvectors[M]} ]


it should return true. Although, you may need to use

KroneckerProduct[Conjugate@#2,#2]


if your matrices are complex. But, as J.M. pointed out, it is preferable to use Eigensystem. Also, if some of your eigenvalues have multiplicities greater than 1, the corresponding eigenvectors are linearly independent, not orthogonal.

Edit: To orthogonalize your eigenvectors, simply use Orthogonalize on them. Since eigenvectors with different eigenvalues are guaranteed to be orthogonal, this won't effect the order, but will give you a reasonable subspace.

The above code is valid if the matrix, $M$, is non-defective in a numerical sense, i.e. it can't be nearly defective, such as

$$\begin{pmatrix}1 & 15 \\ \epsilon & 1\end{pmatrix}$$

where $\epsilon$ is very small and close to the limits machine precision. However, if the above holds, and it barring precision problems, it holds for normal and Hermitian matrices, then the spectral decomposition is simply

$$\mathbf{M} = \sum^N_i \lambda_i \vert \lambda_i \rangle \langle \lambda_i \vert$$

where $\vert \lambda_i \rangle \langle \lambda_i \vert$ is the outer product of the $i^\text{th}$ eigenvector with itself.

• The situation is even worse if OP's matrices are defective. At the very least, if OP has Hermitian matrices, the multiple eigenvalues are not so problematic. – J. M. will be back soon Feb 16 '12 at 1:52
• Proof by example isn't a very good idea if you ask me. – David Feb 16 '12 at 1:52
• @David sorry, I disagree. I'm merely restating the spectral decomposition theorem, which allows you to rewrite the matrix as a sum of outer products of its eigenvectors. Yes, it requires that the matrix be non-defective, which I have added to my answer. – rcollyer Feb 16 '12 at 2:07
• @David: for the Hermitian case at least, it's instructive to compare the results of Eigensystem[] and SchurDecomposition[]... :) – J. M. will be back soon Feb 16 '12 at 2:09
• @rcollyer "I was not thinking about everyone else" — I think it's better to write for the third person (random Googler), especially in general questions like this, so that the full context is available (they won't know that the OP's questions are generally about QM). – rm -rf Feb 16 '12 at 4:36

Mathematica orders the results differently depending on what kind of data is in the matrix.

For example, m = { {h, t, 0, t}, {t, h, t, 0}, {0, t, h, t}, {t, 0, t, h} }

has Eigensystem (h h h-2t h+2t {0,-1,0,1} {-1,0,1,0} {-1,1,-1,1} {1,1,1,1})

But n = { {0, 1, 0, 1}, {1, 0, 1, 0}, {0, 1, 0, 1}, {1, 0, 1, 0} }

has Eigensystem (-2 2 0 0 {-1,1,-1,1} {1,1,1,1} {0,-1,0,1} {-1,0,1,0})

Mathematica uses rows as vectors, not columns. Since I'm used to vectors being columns, I normally Transpose[] my new matrix of Eigenvectors[]. Also, depending on what you are trying to solve, you might want to Orthogonalize[] the eigenvectors which have degenerate eigenvalues after having Normalize[]'d them.

• You have to use Transpose anyway to transform into diagonal basis. Additionally, Orthogonalize produces an orthonormal set of vectors, so using Normalize is an unnecessary additional step. – rcollyer Feb 16 '12 at 2:33