# Ordering of Eigenvalues and Eigenvectors in MATLAB

The following MATLAB function produces the Eigenvalues and Eigenvectors of matrix X.

[V,D] = eig(X) produces a diagonal matrix D of eigenvalues and a
full matrix V whose columns are the corresponding eigenvectors so
that X*V = V*D.


My questions are:

1. Does this mean that the first (or principal or dominant) eigenvector lay on the last column of V? NOTE: the author says that, all the coefficients of the dominant eigenvector are positive and that the remaining eigenvectors (the rest of columns) must have components that are negative, in order to be orthogonal (what does this mean) to u^(i);
2. Regarding the "corresponding eigenvecrtors", do we read them "column-by-column" OR "row-by-row"?
3. Do eigenvalues-eigenvectors come in pairs? If yes, and considering the above, then does the corresponding eigenvalue lay on the bottom-right of matrix D?
4. Actually, I want eigenvalues and their corresponding eigenectors in decreasing order, and then select the, 2 say, "most significant" ones. What I should do?
5. Out of curiosity, but what does it mean "the two times-series Fi and Fi' are uncorrelated in the sense that their empirical correlation vanishes for i != i' ??? How to check that in MATLAB?

LOTS of questions, I know, but I would REALLY appreciate if you could help me answer some of them!

• Concerning the last question check this wiki article en.wikipedia.org/wiki/Cross-correlation – Paul Jul 15 '12 at 16:41
• The help blurb you quote states that the eigenvectors are columns of V. – David Ketcheson Jul 16 '12 at 10:19
• can i extract eigen value in simmilar way as we can extract any matrix element – user12022 Dec 8 '14 at 14:14
• There is a matrix where eigenvalues are ordered: math.stackexchange.com/questions/156035/… – Mats Granvik Sep 14 '15 at 14:11

Let's gather all the answers here. I suppose your matrix is symmetric, since you say that the eigenvectors are orthogonal and try to order the eigenvalues.

1. No, the eigenvalues could come in any order; there is no guarantee that they are ordered.
1bis. There are some classes of matrices (such as Z-matrices or nonnegative matrices) for which it is known that the largest or smallest eigenvector is nonnegative. That must be your case.
1ter. If another eigenvector were to be nonnegative, then the scalar product with the dominant eigenvector $u^{(1)}$ would be positive, as it's the sum of nonnegative terms, one of them at least positive.

2. The columns of the returned $V$ are the eigenvectors.

3. Yes, they come in pair, in the sense that $D(i,i)$ is the eigenvalue relative to $V(:,i)$. This follows from $X*V=V*D$, if you think about it.
3bis. As written above, the eigenvalues are not returned in a specific order. If you wish you can sort $D$ and $V$ conformably using these commands:

 [uselessVariable,permutation]=sort(diag(D));

 

D=D(permutation,permutation);V=V(:,permutation); 

4. I guess that "most significant" means larger. This means the last two columns of $V$, after you reorder as above.

5. Check cross-correlation on Wikipedia. This statement probably means that the sample covariance is zero, i.e., $\frac{1}{n}\sum_{t=1}^n (\phi_t-\mu) (\phi'_t-\mu)'^T=0$, where $\mu$ and $\mu'$ are the means of the two time series. If you wish to verify this experimentally, I guess you'll have a hard time getting an exact zero out of Matlab, since this sum converges quite slowly to its asymptotical value usually. Consider yourself lucky if you have 2 significative digits.

• Since R2009b you can use the tilde as a placeholder for ignored return arguments. E.g. [~,permutation]=sort(diag(D));. – Doug Lipinski Dec 8 '14 at 14:56
• Is it not rather sort( abs(diag(D)), 'descend' ) instead? – Jonathan H Dec 15 '16 at 1:33

At least in the older versions of Matlab, eig didn't sort the eigenvalues. (For complex eigenvalues there is not even a natural ordering.)

Thus it is safer to pick the wanted eigenvalue indices $i$ by inspecting all eigenvalues, and get the corresponding eigenvectors as the columns $V(:,i)$.

Actually each diagonal element (i,i) of matrix D (i.e. eigenvalue) corresponds to ith column of matrix V. That is the the higher value of D(i,i) the more important the corresponding eigenvector.

MatLab function eig(X) sorts eigenvalues in the acsending order, so you need to take the last two colmns of matrix V

Also do remember that if you try to perform factor analysis you can simply use MatLab's princomp function or center the data before using eig.

The signs of components for the first eigenvector is not defines anyhow (in case X is nonsingular and symmetric, e.g. correlation matrix as in factor analysis)

• Could you please explain more detailed the "...or center the data before using" and the other one which is about "the signs of components"... – eualin Jul 15 '12 at 16:45
• He means subtracting out the mean of each column. Also, svd, princomp, and eigs (which can be used to just take the 2 largest) all sort in descending order. So make sure to pay attention to which you're using. – John Jul 15 '12 at 16:48
• eigenvalues returned by eig are NOT sorted: stackoverflow.com/questions/13704384/… (the eigenvectors are of course still in matching order). Even if you do it manually, you need to keep in mind how sort works on complex numbers (sorts by magnitude, ie abs()). Note that svd on the other hand returns singular values in decreasing order (stated in the docs). – Amro Feb 20 '14 at 21:31

Given the formula, you should read the vectors column-by-column.

The value associated with the i-th vector is the i-th value on the diagonal of D.

I am not sure the eigenvalues or egenvectors are ordered, and the "order" you are talking about doesn't seem clear to me...

If I assume you want to order the vectors by decreasing eigenvalues, then simply switch the right columns in V and the right rows and columns in D.