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?
How to obtain Eigenvalues with maximum precision in Mathematica
2 Answers
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.
-
0You beat me to it! +1 – 2011-12-03
-
0The 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. – 2011-12-03
-
2Ah, 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. – 2011-12-03
-
0@ J.M. Here is the matrices http://www.2shared.com/file/ce8hiO6b/Matrices_A_and_B.html can you test it what is the best solution and fastest in same time. You suggested CharasteristicPolynomial[] but how to do that? – 2011-12-03
-
0I'd rather not look, as I don't have *Mathematica* at the moment. Just answer some questions for me. How big are those two matrices, and what does `MatrixRank[]` return for both of them? – 2011-12-03
-
0MatrixRank[A] got 31 MatrixRank[B] got 33. Both of them are symmetric. – 2011-12-03
-
0@J.M.: `{Dimensions@#, MatrixRank@#} & /@ {A, B}` returns `{{{33, 33}, 31}, {{33, 33}, 33}}`, so `B` is invertible. – 2011-12-03
-
0Thanks Simon. @George, you can try timing either of `Eigenvalues[Inverse[B].A]` or `x /. Solve[CharacteristicPolynomial[{A, B}, x] == 0, x]`. – 2011-12-03
-
0Thank you J.M. I got it in form Root... very big, is it possible to extract it or present in numerical form from here? – 2011-12-03
-
1@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. – 2011-12-03
-
1Now you're being confusing @George. First you want them exact, and now you want them approximate... – 2011-12-03
-
0No, exact is in form which I can not see, but I was afraid that numerical has an error. So I wanted solution without error, but now I can not see. Actually I am not sure on which decimal is error when I just use command Eigenvalues. Thank you again very much Mr J.M. for this effort. Big respect anyway! – 2011-12-03
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!
-
0but there is a problem with Eigenvalues[N[A,B],100]]; Mathematica doesn't accept. Here are the matrices completely reduced on fraction form http://www.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? – 2011-12-03
-
0I 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`](http://reference.wolfram.com/mathematica/ref/Root.html) 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[]`. – 2011-12-03
-
0J.M. suggest x /. Solve[CharacteristicPolynomial[{A, B}, x] == 0, x], in that case I got the solutions but how to see it in numerical form because it gives in form Root...# – 2011-12-03
-
0@George: The `Solve[CharacteristicPolynomial[...]]` is essentially what `Eigenvalues` does when working with exact expressions. In general there will be no "nice" way of writing the roots of a 31st degree polynomial, so just use `N[expr, prec]` to get the numerical values to what ever precision you needed. – 2011-12-03
-
1Or use `Eigenvalues[N[{M, A}, prec]]` from the very beginning - and forget about exact expressions. – 2011-12-03
-
0I don't understand what George wants anymore... for a matrix that big, I'd do `Eigenvalues[N[{M, A}, prec]]` directly and not bother about exact expressions... – 2011-12-03
-
2@J.M.: [He hasn't got a good record](http://stackoverflow.com/users/1031298/george-mills) on asking [clear questions](http://math.stackexchange.com/users/15589/george). (I probably should stop bothering trying to answer them...) – 2011-12-03
-
0We both got suckered, man. :) Thanks for the heads-up. – 2011-12-03
-
0Thank you very much Simon again for everything, big respect! Regards! – 2011-12-03
-
0@Simon Once again Eigenvalues[N[{A, B}, 50]] // MatrixForm got an error with "General::unfl: Underflow occurred in computation. >>" and because of that I thought that there is big difference between exact and numerical solution. Check, I think that some error appears, maybe not something serious Simon. But for any case I want to tell you. – 2011-12-03
-
1@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. – 2011-12-03
-
0@Simon Yes you are right very small error. There is just message "General::unfl: Underflow occurred in computation." when I use Eigenvalues[N[{A, B}, 50]] but I got the solution and think that it is not serious. – 2011-12-03