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?
3 Answers
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:
Eigenvalues[m]
(* {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.
- 234,956
- 30
- 623
- 1,263
-
-
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. – Simon Dec 08 '14 at 02:20 -
@Simon.Z To take the smallest (negative) ones, you can take the eigenvalues of
-minstead ofm, 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/ – Szabolcs Dec 08 '14 at 03:52
ClearAll[rF];
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.}}} *)
rF[mat,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.}} *)
- 394,356
- 18
- 477
- 896
-
Yeah, so the conclusion is there is no quick function to tackle this problem. I should write several lines to do this. – Simon Dec 07 '14 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]}]
- 68,936
- 4
- 101
- 191
-
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. – Simon Dec 07 '14 at 15:37
-
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. – bill s Dec 07 '14 at 15:39
-
What if I want to get n-th largest eigenvalues considering sign of values? – Simon Dec 07 '14 at 15:42
-
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$? – bill s Dec 07 '14 at 15:44
-
Well, symmetric matrix gives real eigenvalue all the time. And if I use Sort[], how to find the corresponding eigenstates? – Simon Dec 07 '14 at 15:47
Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign!
– Dec 07 '14 at 15:35