I have a real symmetric matrix m (i.e. its eigenvalues are all real). Eigenvalues[m, {k}] will find the kth largest eigenvalue by magnitude. How can I find the kth largest, taking the sign into account? How can I find the corresponding eigenvectors?

  • $\begingroup$ This question is hard to read/understand. Consider rephrasing it. $\endgroup$
    – Szabolcs
    Commented Dec 7, 2014 at 15:28
  • $\begingroup$ I rewrote it a little. Actually the title is the whole story. $\endgroup$
    – Simon
    Commented Dec 7, 2014 at 15:34
  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$
    – user9660
    Commented Dec 7, 2014 at 15:35
  • $\begingroup$ Looking at all the confusion below, it would have been useful to explicitly mention in the question that you need to take the sign into account (not largest/smallest based on magnitude). You didn't mention that the matrix is symmetric and real either. Please take the time to write up the question precisely, then I'll post a simple solution. We are trying to make sure that the questions here are useful not only for the original asker but also for others in the future. $\endgroup$
    – Szabolcs
    Commented Dec 7, 2014 at 17:34
  • $\begingroup$ Okay, I tried to rephrase your question based on how I understood it. Please check that this is what you meant, and whether my answer solves your problem. $\endgroup$
    – Szabolcs
    Commented Dec 7, 2014 at 17:47

3 Answers 3


In general, eigenvalues are not real. When asking for the kth largest eigenvalue, by default Mathematica sorts eigenvalues based on magnitude.

When using the Arnoldi method, it is possible to specify how eigenvalues should be sorted: based on magnitude, the real part, or imaginary part. This is described under the Method option of Eigenvalues in the version 10 documentation.

For example, let's create a real symmetric matrix:

m = RandomReal[1, 15 {1, 1}];
m = m + Transpose[m];

These are all the eigenvalues, sorted decreasingly by magnitude:

(* {14.8003, 2.73255, -2.63109, -2.51576, 1.87506, -1.58716, \
1.43875, 1.243, -1.20684, -0.947984, 0.630826, -0.550382, 0.491025, \
0.283469, -0.0578321} *)

We can instead request the 3 largest by real part:

Eigenvalues[m, 3, Method -> {"Arnoldi", "Criteria" -> "RealPart"}]
(* {14.8003, 2.73255, 1.87506} *)

Use Eigensystem the same way to obtain both eigenvalues and eigenvectors.

  • $\begingroup$ Thanks for the helpful answer and edit. Your answer solved my problem. $\endgroup$
    – Simon
    Commented Dec 8, 2014 at 2:05
  • $\begingroup$ There are still some questions. "Arnoldi" method seems can only get half of the eigenvalues for matrix, how can I get the smallest eigenvalues by this method. $\endgroup$
    – Simon
    Commented Dec 8, 2014 at 2:20
  • $\begingroup$ @Simon.Z To take the smallest (negative) ones, you can take the eigenvalues of -m instead of m, then multiply them by -1. The Arnoldi method will usually only work for getting the few largest (or few smallest) eigenvalues, so this is indeed a limitation/ $\endgroup$
    – Szabolcs
    Commented Dec 8, 2014 at 3:52
rF[mat_, n_] := With[{es = Eigensystem[mat]},
  With[{m = Transpose@es, o = Ordering[N@First@es, {n}]}, First@m[[o]]]]

mat = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
{vals, vecs} = Eigensystem[mat] // N
(* {{16.1168,-1.11684,0.},{{0.283349,0.641675,1.},{-1.28335,-0.141675, 1.},{1.,-2.,1.}}} *)


$$ \left\{-\frac{3}{2} \left(\sqrt{33}-5\right),\left\{\frac{1}{22} \left(-11-3 \sqrt{33}\right),\frac{1}{44} \left(11-3 \sqrt{33}\right),1\right\}\right\}$$

rF[mat, 1] // N
(* {-1.11684,{-1.28335,-0.141675,1.}} *)

rF[mat, 2] // N
(* {0.,{1.,-2.,1.}} *)
rF[mat, 3] // N
(* {16.1168,{0.283349,0.641675,1.}} *)
  • $\begingroup$ Yeah, so the conclusion is there is no quick function to tackle this problem. I should write several lines to do this. $\endgroup$
    – Simon
    Commented Dec 7, 2014 at 16:12
  • $\begingroup$ @Simon.Z, afaik right. $\endgroup$
    – kglr
    Commented Dec 7, 2014 at 16:12

You can get just the nth largest Eigenvalue using the syntax

m = RandomReal[{-1, 1}, {5, 5}]
Eigenvalues[m, {3}]

Observe that this returns the third largest eigenvalue (i..e, the one with the third largest Abs[]).

Eigenvectors[m, {3}]

gives the corresponding eigenvector. Accordingly, you can get the smallest eigenvalues/vectors with

Eigenvalues[m, {Length[m]}]
  • $\begingroup$ I find Eigenvalues[m,{3}] is actually Eigenvalues[m,3][[3]], it seems the result is wrong sometimes. Especailly when there are both positive and negative eigenvalues. $\endgroup$
    – Simon
    Commented Dec 7, 2014 at 15:37
  • $\begingroup$ The eigenvalues are returned in sorted order, sorted by the Abs[]. That would be the normal meaning of "larger" and "smaller" when dealing with complex numbers. But this does remove the need to explicitly calculate them all. $\endgroup$
    – bill s
    Commented Dec 7, 2014 at 15:39
  • $\begingroup$ What if I want to get n-th largest eigenvalues considering sign of values? $\endgroup$
    – Simon
    Commented Dec 7, 2014 at 15:42
  • $\begingroup$ Then you'll need to sort them yourself. Eigenvalues are, in general, complex valued, and "sign" isn't something that nicely applies to complex-values. Is +5-10$i$ greater or less than -3+20$i$? $\endgroup$
    – bill s
    Commented Dec 7, 2014 at 15:44
  • $\begingroup$ Well, symmetric matrix gives real eigenvalue all the time. And if I use Sort[], how to find the corresponding eigenstates? $\endgroup$
    – Simon
    Commented Dec 7, 2014 at 15:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.