Eigenvalues in MATLAB

Spencer picture Spencer · Jul 20, 2010 · Viewed 19.6k times · Source

In MATLAB, when I run the command [V,D] = eig(a) for a symmetric matrix, the largest eigenvalue (and its associated vector) is located in last column. However, when I run it with a non-symmetric matrix, the largest eigenvalue is in the first column.

I am trying to calculate eigenvector centrality which requires that I take the compute the eigenvector associated with the largest eigenvalue. So the fact that the largest eigenvalue appears in two separate places it makes it difficult for me to find the solution.

Answer

Amro picture Amro · Jul 20, 2010

What I usually do is:

[V D] = eig(a);
[D order] = sort(diag(D),'descend');  %# sort eigenvalues in descending order
V = V(:,order);