11
$\begingroup$

I have a (non-sparse) $9 \times 9$ matrix and I wish to obtain its eigenvalues and eigenvectors. Of course, the eigenvalues can be quite a pain as we will probably not be able to find the zeros of its characteristic polynomial.

Actually, what I really want is find the eigenvector belonging to the largest eigenvalue. Would the following code give me this: Eigenvectors[matrix, 1]?

How does Mathematica do this? Is there some kind of algorithm of which's existence I am unaware that computes the eigenvector belonging to the largest eigenvalue?

Can the largest eigenvalue be computed numerically (in modulus or even throw away all the complex ones), and then the eigenvectors pseudo-analytically using Eigenvectors?

Added: The matrix is symbolical.

$\endgroup$
1
  • 1
    $\begingroup$ I am in the old post here. Have anyone found the way to generate the eigenvectors and eigenvalues as ordered? I mean I get the eigenvector matrix but the eigenvalues are not for the corresponding eigenvectors. New to mathematica any help appreciated $\endgroup$
    – user75592
    Nov 7, 2020 at 1:46

4 Answers 4

9
$\begingroup$

The function to obtain both the eigenvalues and the eigenvectors is Eigensystem. Use it as {eigVals,eigVecs} = Eigensystem[matrix].

If the matrix is symbolic, then the output (if you wait long enough for it to churn out an answer!) will only be as a list of general solutions for the roots of a 9th order polynomial with unknown coefficients, and there are no closed form solutions for polynomials with orders greater than 4. The results will not have any particular ordering.

On the other hand, a 9x9 numerical matrix is a piece of cake (even if you were to solve the characteristic polynomial), so you should have no problems.

To obtain the largest (first) eigenvalue and the corresponding eigenvector, use the optional second argument as Eigensystem[matrix, 1]. Here's an example (with a smaller matrix to keep the output small):

mat = RandomInteger[{0, 10}, {3, 3}];
{eigVals, eigVecs} = Eigensystem[mat] // N

(* Out[1]= {{21.4725, 6.39644, 0.131054}, {{1.3448, 0.904702, 1.}, 
            {0.547971, -1.99577, 1.}, {-0.935874, -0.127319, 1.}}} *)

{eigVal1, eigVec1} = Eigensystem[mat, 1] // N
(* Out[2]= {{21.4725}, {{1.3448, 0.904702, 1.}}} *)
$\endgroup$
17
  • $\begingroup$ Well, the matrix is not numerical but largely symbolical. Mathematica is unable to obtain the eigenvalues except if I set a few terms to $0$. If I ask Mathematica to output the characteristic polynomial it claims it consists out of more than 50k terms! $\endgroup$
    – JT_NL
    Feb 19, 2012 at 18:41
  • 1
    $\begingroup$ Thanks! My matrix is symbolical but I do have numerical values for the parameters and hence I have a numerical matrix. How does Mathematica find eigenvalues for a $9 \times 9$ matrix? How can it solve the characteristic polynomial? Anyway, I wanted to have symbolic expressions for the eigenvalues as I wanted to let one parameter vary and plot the result. Would the best way now be (using Mathematica) that for a few data points I compute the eigenvalues and make a plot of that? $\endgroup$
    – JT_NL
    Feb 19, 2012 at 18:59
  • $\begingroup$ @JonasTeuwen What is the structure of your matrix? Which of the 81 elements is your free parameter (and the rest numerical)? I'm afraid, I don't know how Mathematica calculates the eigenvalues symbolically. $\endgroup$
    – rm -rf
    Feb 19, 2012 at 19:05
  • $\begingroup$ @JonasTeuwen Is the only reason you want a symbolic solution that you want to plot it? If so, use With[{mat = matrix}, f[x_?NumericQ] := Eigenvalues[mat, 1]], then Plot[f[x], {x, xmin, xmax}] (assuming that x is the parameter according to which you want to plot). Don't compute it for selected data points manually, just let Plot work it's adaptive sampling magic. Also note that which root is the largest might easily depend on the parameter, so the plot could have a discontinuous derivative. $\endgroup$
    – Szabolcs
    Feb 19, 2012 at 19:17
  • $\begingroup$ @JonasTeuwen That With from my previous comment won't work for injecting the value (localization kicks in), but just copy the matrix expression manually into Eigenvalues when you define the function. $\endgroup$
    – Szabolcs
    Feb 19, 2012 at 19:45
7
$\begingroup$

If the matrix is completely numerical (not symbolic), then Eigenvalues will return eigenvalues by descending magnitude. Therefore Eigenvalues[matrix, 1] will always give the largest eigenvalue and Eigenvector[matrix, 1] will give the corresponding eigenvector. As R.M. said, both can be obtained at the same time using Eigensystem.

There are different numerical methods for obtaining the eigenvector that corresponds to the largest eigenvalue (by magnitude), the most common being power iteration.

If the matrix is symbolic, the eigenvalues/vectors are not ordered (as far as I know).

$\endgroup$
1
  • $\begingroup$ If the matrix is symbolic, the eigenvectors are unordered, correct. $\endgroup$ Feb 20, 2012 at 9:42
4
$\begingroup$

Re the question as to how Mathematica finds eigenvalues: in the Documentation Center look up "implementation"; you'll find a link to the page tutorial/SomeNotesOnInternalImplementation. And there, in the section Exact Numerical Linear Algebra you'll find the explanation, "Eigenvalues works by interpolating the characteristic polynomial."

$\endgroup$
3
$\begingroup$

Eigensystem will give you the eigenvalues and eigenvectors, the rest is a matter of sorting and extracting that data.

(* Calculates the eigenvector with the largest eigenvalue *)
largestEV[m_] := Sort[
    Transpose@Eigensystem[m],
    #1[[1]] < #2[[1]] &
][[1, 2]]

m = {{1, 1, 0}, {0, 2, 0}, {0, 2, 3}}
largestEV[m]
 {1, 0, 0}
$\endgroup$
5
  • 4
    $\begingroup$ Why complicate when you can use the second argument for Eigensystem? See my answer... $\endgroup$
    – rm -rf
    Feb 19, 2012 at 18:46
  • $\begingroup$ This generalizes easier, suppose you wanted the eigenvector closest to the average eigenvalue etc. Also, I'm not sure how the standard ordering works for complex eigenvalues. $\endgroup$
    – David
    Feb 19, 2012 at 18:49
  • 1
    $\begingroup$ For complex eigenvalues, the ordering is decreasing Abs[eigenvalues] $\endgroup$
    – rm -rf
    Feb 19, 2012 at 18:56
  • $\begingroup$ Why would it generalize easier? Eigensystem[mat, All] $\endgroup$
    – user21
    Feb 20, 2012 at 8:55
  • $\begingroup$ @ruebenko That's what I did. $\endgroup$
    – David
    Feb 20, 2012 at 17:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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