Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question
add comment

5 Answers

up vote 3 down vote accepted

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.}}} *)
share|improve this answer
    
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! –  Jonas Teuwen Feb 19 '12 at 18:41
    
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? –  Jonas Teuwen Feb 19 '12 at 18:59
    
@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. –  rm -rf Feb 19 '12 at 19:05
    
@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. –  Szabolcs Feb 19 '12 at 19:17
    
@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. –  Szabolcs Feb 19 '12 at 19:45
show 11 more comments

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).

share|improve this answer
    
If the matrix is symbolic, the eigenvectors are unordered, correct. –  kkm Feb 20 '12 at 9:42
add comment

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."

share|improve this answer
add comment

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}
share|improve this answer
4  
Why complicate when you can use the second argument for Eigensystem? See my answer... –  rm -rf Feb 19 '12 at 18:46
    
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. –  David Feb 19 '12 at 18:49
1  
For complex eigenvalues, the ordering is decreasing Abs[eigenvalues] –  rm -rf Feb 19 '12 at 18:56
    
Why would it generalize easier? Eigensystem[mat, All] –  user21 Feb 20 '12 at 8:55
    
@ruebenko That's what I did. –  David Feb 20 '12 at 17:54
add comment

I believe Mathematica uses some techniques beyond our books, for even matrix with clustered and multiple eigenvalues and lack of eigenvectors can be solved. Why?

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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