Search code examples
matlabeigenvalueeigenvector

Are the largest eigenvectors sorted by absolute eigenvalue?


Say I have a real symmetric matrix, and I want to extract the k largest eigenvectors using eig.

I know I can use eigs instead but that's not the point of my question. I read that they use different algorithms, and the documentation for eigs states explicitly "largest magnitude", which seems to imply that the eigenvalues would be sorted in absolute value, especially because apparently the sign of the eigenvector/values does not matter.

However I also read that ordering the eigenvectors should be done according to the ranking of the eigenvalues, with sort(diag(D)); no absolute value here (and no assumption about positiveness for the matrix).

  1. I think that either the latter post is wrong, or Matlab's documentation for eigs is wrong or misleading when using the words "largest magnitude", is that right? Or are they both right and I misunderstood something?

  2. To clarify then, the "largest" eigenvectors should be sorted according to the absolute eigenvalue, correct?


Solution

    1. The latter question you reference is discussing eig, which uses direct methods intended for general, dense matrices; you are discussing eigs, which uses iterative methods intended for general, sparse matrices.

      eig will return the eigenvalues in the order found by the direct method. In general, this means random ordering. For real symmetric matrices, the ordering from the direct method appears to generate the eigenvalues from most negative to most positive.

      eigs will return k eigenvalues and vectors with the largest/smallest magnitude/real part/imaginary part (user-specified). However, as noted, "eigs does not always return sorted eigenvalues and eigenvectors. Use sort to explicitly sort the output eigenvalues and eigenvectors in cases where their order is important."

    2. Typically, yes, largest (absolute) magnitude. Though sort can be used to permute the eigenvalues into any required order.