# Getting different eigenvalues for same matrix? [closed]

Im trying to find eigenvalues for the matrix

\begin{bmatrix} 2 & -1 & -1 \\ -1 & 1 & 1 \\ -1 & 1 & 4 \end{bmatrix}

Finding the eigenvalues using the Eigenvalues function I get:

N@Eigenvalues[ {
{2, -1, -1},
{-1, 1, 1},
{-1, 1, 4}
} ]


And it returns

{4.8662, 1.78924, 0.344558}


However, when I try to solve it by hand, and using the Characteristic Polynomial function

 CharacteristicPolynomial[ {
{2, -1, -1},
{-1, 1, 1},
{-1, 1, 4}
} , \[Lambda]]


I get $$3 - 11 \lambda + 7 \lambda^2 - \lambda ^3$$

Solving it for zero I get non real answers.

N@Solve[3 - 11 \[Lambda] + 7 \[Lambda]^2 - \[Lambda]^3 ==
0, \[Lambda]]

{{\[Lambda] -> 4.8662 + 7.40149*10^-17 I},
{\[Lambda] ->
0.344558 + 4.44089*10^-16 I},
{\[Lambda] ->
1.78924 - 4.44089*10^-16 I}}


## closed as off-topic by Daniel Lichtblau, Edmund, MarcoB, garej, LCarvalhoSep 28 '17 at 9:38

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Daniel Lichtblau, Edmund, garej, LCarvalho
If this question can be reworded to fit the rules in the help center, please edit the question.

• bugs is a tag to be used only when other people have confirmed your observations to be a bug. In this case, it isn't: the tiny imaginary parts are on the order of roundoff error. – J. M. will be back soon Sep 27 '17 at 4:22
• If you use NSolve[charpoly == 0, \[Lambda]] instead of N@Solve[charpoly == 0, \[Lambda]] you get all real solutions. – aardvark2012 Sep 27 '17 at 4:24
• The following is a guess, as you had not provided the code you used to get the roots of the eigenpolynomial: if you had used Solve[] and applied N[] to the results, you might want to recall that the results are an instance of casus irreducibilis; you are then making Mathematica compute a real result from complex numbers, and thus the tiny imaginary part is but an artifact. – J. M. will be back soon Sep 27 '17 at 4:26
• Use ComplexExpand: Solve[3 - 11 \[Lambda] + 7 \[Lambda]^2 - \[Lambda]^3 == 0, \[Lambda]] // ComplexExpand // N – Bob Hanlon Sep 27 '17 at 4:47
• Really this seems to be a question about the math and not Mathematica. – Daniel Lichtblau Sep 27 '17 at 17:00

Drop the N and look at the symbolic results.

Eigenvalues gives an answer like

Root[-3 + 11 #1 - 7 #1^2 + #1^3 &, 1]


Solve gives

7/3 - (8 (1 + I Sqrt[3]))/(3 (37 + 3 I Sqrt[303])^(1/3)) -
1/6 (1 - I Sqrt[3]) (37 + 3 I Sqrt[303])^(1/3)


This is no surprise because there is no reason to assume that two distinct functions use the same methods. The two results are equivalent, just expressed in different forms.

Since they are written in different forms, again it is not a surprise that computing then numerically gives slightly different results due to roundoff errors.

The second form contains the imaginary unit, but this does not mean that it has a non-zero imaginary part. However, it is entirely expected that when computing a numerical approximation, the imaginary part will only be almost zero.

Mathematica uses different numerical methods to compute the value of Root, and thus arrives to a slightly different numerical approximation. The difference between the results is on the order of $10^{-16}$ though, which is the precision limit of machine numbers.

To deal with these situations, look up Chop, or try computing these expressions to more digits using the second argument of N. This will also trigger Precision tracking and will give you more reliable results. Notice that the imaginary part never disappears, but the more digits you compute, the smaller it gets. Also notice that the imaginary part is smaller than the Accuracy of the result.