# How to obtain Eigenvalues with maximum precision in Mathematica

One short question. If we have two matrices in fractional form, how to obtain the Eigenvalues[{A,B}] with maximum precision or get it also in fraction form?

-

The problem is that Eigenvalues[] does not support matrices with exact entries for the case of the generalized eigenproblem $\mathbf A\mathbf x=\lambda\mathbf B\mathbf x$. If you want to get exact solutions, and $\mathbf B$ is invertible, just execute RootReduce[Eigenvalues[Inverse[B].A]]; here, one does not have to worry about ill-conditioning as in the inexact case. If $\mathbf B$ is not invertible, but $\mathbf A$ is, then you need RootReduce[1/Eigenvalues[Inverse[A].B]] (the proof that this works is left as an exercise); if both $\mathbf A$ and $\mathbf B$ are singular, things are more complicated, and I'll just tell you to search for "singular pencils" in your favorite search engine.

-
You beat me to it! +1 –  Simon Dec 3 '11 at 1:32
The situation was once similar to that of SingularValues[]/SingularValueList[]; the solution to that case was Eigenvalues[Transpose[A].A]. But of course, this is no longer needed in new Mathematica versions. –  Ｊ. Ｍ. Dec 3 '11 at 1:38
Ah, what the heck: lucky for George, Wolfram had the foresight to have CharacteristicPolynomial[] support pencils; for the singular pencil case, compute the characteristic polynomial, use Solve[], and pad the results with Infinity or Indeterminate as needed, depending on the results of MatrixRank[] on the two given matrices. –  Ｊ. Ｍ. Dec 3 '11 at 2:43
@George: Just use N[Root[...], prec] to get the precision (prec) that you need. In general there will be no "nice" way of writing the roots of a 31st degree polynomial. –  Simon Dec 3 '11 at 12:50
Now you're being confusing @George. First you want them exact, and now you want them approximate... –  Ｊ. Ｍ. Dec 3 '11 at 12:50

The Mathematica command Eigenvalues[{M,A}] finds the generalized eigenvalues $\lambda$ that satisfy the equation $M v = \lambda A v$, for eigenvectors $v$. Unfortunately, this version of Eigenvalues does not support calculations with exact numbers or symbolic variables.

One way to proceed is to rearrange the generalized eigenvalue equation to $A^{-1} M v = \lambda v$, then you can just use Eigenvalues[Inverse[A].M], provided $A$ is invertible.

Another way to get exact results is to solve it numerically with high precision then use an integer relation algorithm such as RootApproximant to identify the polynomial.

eVals = Eigenvalues[N[{M, A}, 100]];
RootApproximant[eVals, Method -> {"DegreeCost" -> 3}]


but this probably isn't a very sensible way to approach the problem!

-
but there is a problem with Eigenvalues[N[A,B],100]]; Mathematica doesn't accept. Here are the matrices completely reduced on fraction form 2shared.com/file/ce8hiO6b/Matrices_A_and_B.html but what is the exact solution Eigenvalues[A,B]? And when I got the solution in form $$\text{Root}\left[162904315798572+67352586131695 \text{\#1}-20676989596643 \text{\#1}^2\right.$$ $$\left.-3696503332225 \text{\#1}^3+1238108808324 \text{\#1}^4-11958953768 \text{\#1}^5+53788 \text{\#1}^6\&,4\right]$$ how it looks like in numerical form? –  George Dec 3 '11 at 12:18
I just looked at your matrices. The exact Eigenvalues[Inverse[A].M] works (took a couple of minutes on my machine) and yields Root objects of degree 31 with massive integer coefficients (~1000 digits). RootApproximant won't find these unless you use insane precision. A Root expression represents the abstract root of a polynomial. The order that they are defined in is defined in the documentation. They can be evaluated to arbitrary (within reason) precision using N[]. –  Simon Dec 3 '11 at 12:37
Or use Eigenvalues[N[{M, A}, prec]] from the very beginning - and forget about exact expressions. –  Simon Dec 3 '11 at 12:52
@J.M.: He hasn't got a good record on asking clear questions. (I probably should stop bothering trying to answer them...) –  Simon Dec 3 '11 at 12:58
@George: Yeah, I don't think that in this case the error is anything to worry about. You can compare Eigenvalues[N[{A, B}, 50]] with N[Eigenvalues[Inverse[B].A], 50] to check. Apart from possible differences in ordering, they should be the same up to a small numerical error. –  Simon Dec 3 '11 at 14:11