2
$\begingroup$

I am trying to plot eigenvalues of a matrix. I get some errors like “precision may be lost”. As a result, there are some unwanted jumps in the plot. Any suggestion of what am I doing wrong?

Thanks

$\endgroup$

1 Answer 1

3
$\begingroup$

You are running into numerical precision trouble. Use exact numbers instead. With all your definitions, change the calculation of eigenvalues to:

eigenvalues = Eigenvalues[Rationalize[H, 0]]

You can then plot them as you expected, although the following naïve plot is remarkably slow:

Plot[
  Evaluate@N@eigenvalues, {bx, -0.2, 0.2}, 
  Frame -> True, FrameLabel -> {"B", "y"}
]

eigenvalues - no zero crossings

$\endgroup$
2
  • $\begingroup$ Thank you very much for your help. Would you please explain briefly what does "Evaluate@N@" do in the last line? I could not google it. $\endgroup$
    – sara sam
    Jan 4, 2021 at 23:47
  • 1
    $\begingroup$ @sarasam The results from Eigenvalues are symbolic and the plotting was very slow. N@eigenvalues turns them into machine-precision entities. Because of the Hold attribute of Plot, I added Evaluate to force pre-evaluation of its argument, and make sure that Plot was dealing with the machine precision argument. I am not sure that it made a great difference in terms of plotting speed. You could remove it and see how king it takes to plot, I.e. Plot[eigenvalues, ...]. $\endgroup$
    – MarcoB
    Jan 5, 2021 at 14:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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