I am using Plot to look at the eigenvalues of a matrix, and find that in some circumstances I get artifacts. For example

H = {{x, -g}, {g, -x}};
Plot[Eigenvalues[H] /. g -> 1, {x, -4, 4}]

gives me

{-Sqrt[-g^2 + x^2], Sqrt[-g^2 + x^2]}

good plot


H = {{x, -1}, {1, -x}};
Plot[Eigenvalues[H], {x, -4, 4}]

gives me

{-Sqrt[-1 + x^2], Sqrt[-1 + x^2]}

bad plot

Fianlly, just to add to the confusion,

Plot[{-Sqrt[-1 + x^2], Sqrt[-1 + x^2]}, {x, -4, 4}]


good plot 2

What's going on here? I thought there would be no difference between these.


When you are using Eigenvalues[H] inside Plot it is evaluated each time for an x, and depending on the matrix the order of the eigenvalues may change as well. Evaluate it before and then plot

H = {{x, -1}, {1, -x}};
ev = Eigenvalues[H]
Plot[ev, {x, -4, 4}]


enter image description here

Or you can try to Sort it

Plot[Sort[Eigenvalues[H]], {x, -4, 4}]
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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