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
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"}
]
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$