Deferent results depending on the input form of the matrix [duplicate]

Why is it so,

N[Eigenvectors[{{1., 0.5, 4.}, {2., 1., 2.}, {0.25, 0.5, 1.}}]]


returns:

{{-0.603584, -0.760468, -0.239532}, {0.301792 -
0.522719 I, -0.760468 + 0. I,
0.119766 + 0.207441 I}, {0.301792 + 0.522719 I, -0.760468 + 0. I,
0.119766 - 0.207441 I}}


whilst

N[Eigenvectors[{{1, 1/2, 4}, {2, 1, 2}, {1/4, 1/2, 1}}]]


returns:

{{2.51984, 3.1748, 1.}, {-1.25992 - 2.18225 I, -1.5874 + 2.74946 I,
1.}, {-1.25992 + 2.18225 I, -1.5874 - 2.74946 I, 1.}}


In other words why two queries with the same input returns two different results, and how to deal with that?

• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! Commented Nov 25, 2014 at 18:06
• From the documentation page of Eigenvectors: Eigenvectors with numeric eigenvalues are sorted in order of decreasing absolute value of their eigenvalues. Two of the eigenvalues are modulus-degenerate, so it is not possible to expect consistent results even if the input was numericized, and in any case, the second input is symbolic, so no sorting is done, which explains the difference. Commented Nov 25, 2014 at 18:08
• The other issue to note in the docs is this : "For approximate numerical matrices m, the eigenvectors are normalized." Commented Nov 25, 2014 at 18:14

Please first take a look at http://reference.wolfram.com/language/tutorial/ExactAndApproximateResults.html

Eigenvalues uses entirely different methods when working with exact or inexact quantities.

mat = {{1, 1/2, 4}, {2, 1, 2}, {1/4, 1/2, 1}};


First notice that the eigenvalues are the same and returned in the same order in the two cases:

Chop@Eigenvalues@N[mat]
(* {3.21736, -0.108681 + 0.829168 I, -0.108681 - 0.829168 I} *)

N@Eigenvalues[mat]
(* {3.21736, -0.108681 + 0.829168 I, -0.108681 - 0.829168 I} *)


Since the algorithms are different, there's no guarantee that they'd come in the same order for the exact and inexact calculations in general.

Causes of differences in eigenvectors:

• the second eigenvalue is degenerate meaning that the eigenvectors are not uniquely determined

• the eigenvectors returned by the exact algorithm are not normalized

• because of precision issues, the inexact result is not perfect and will sometime contain negligible imaginary parts, which can be gotten rid of using Chop.

Comparing the first eigenvector, they're the same save for a constant factor:

First@N@Eigenvectors[mat]/First@Chop@Eigenvectors@N[mat]
(* {-4.1748, -4.1748, -4.1748} *)

• @jano 1. What is the problem that you're trying to solve, precisely? The eigenvalues returned by the two methods are equivalent. 2. Accuracy was just one (minor) aspect I mentioned which makes the result look different, even though they're equivalent. If $\mathbf{x}$ is an eigenvector, so is $\alpha \mathbf{x}$. If an eigenvalue is degenerate, any linear combinations of the corresponding eigenvectors is also an eigenvector. Commented Nov 25, 2014 at 22:38
• Thanks for your comment but the problem is elsewhere. The matrix M={{1., 0.5, 4.}, {2., 1., 2.}, {0.25, 0.5, 1.}} is positive (and reciprocal), thus due to the Perron-Frobenus theorem MUST exist one real, positive eigenvalue (one with the largest module) accompanied by the positive and real eigenvector. So the question is why none of the eigenvectors is positive? In other words the result is inconsistent with the old and recognized theorem... why is it so?
– jano
Commented Nov 25, 2014 at 22:43
• @jano 1. As I understand, you have doubts about the correctness of the result returned by Mathematica. In this case it is best to check it. It's fairly easy to check eigenvectors and eigenvalues: just multiply the eigenvector by the matrix, and see if you get the same result as multiplying it by the eigenvalue. (Yes, in this case it's the same, but it's good practice to verify the results.) 2. The largest eigenvalue is indeed positive and real. The corresponding eigenvector can be made positive and real by multiplying with a constant. There's no contradiction or inconsistency. Commented Nov 25, 2014 at 22:50
• OK, I missed the fact that any multiple of an eigenvector is also an eigenvector. On the other hand the Theorem as formulated here link is very precise: "There exists an eigenvector (...) all components of v are positive" ;)
– jano
Commented Nov 25, 2014 at 23:21