3
$\begingroup$

I'm trying to plot a graph from the eigenvalues of a matrix I created. The graph shows with discontinuities in it and I was looking for some feedback.

Here's the code:

v1 = -4.01*Exp[I*(ka)/2];
v2 = -4.01*Exp[-I*(ka)/2];
v3 = -4.01*Exp[I*(ka)];
v4 = -4.01*Exp[-I*(ka)];
Eo = -8.97;

H = {{Eo, v1, 0, 0, 0, v4}, {v2, Eo, v2, 0, v3, 0},
   {0, v1, Eo, v4, 0, 0}, {0, 0, v3, Eo, v2, 0}, {0, v4, 0, v1, Eo, 
    v1}, {v3, 0, 0, 0, v2, Eo}};
MatrixForm[H]
bs = Eigenvalues[H];
Plot[bs, {(ka), -0.8, 0.8}]

I would really appreciate your help.

$\endgroup$
2

1 Answer 1

3
$\begingroup$

Small numerical errors generate tiny imaginary parts-Solve it with:

Plot[bs // Chop, {(ka), -0.8, 0.8}]

Mathematica graphics

Eventually, answering @MarkMcClure's comment:

b[k_?NumericQ] := Eigenvalues[H /. ka -> k]; 
Plot[Quiet@Table[b[ka][[i]], {i, 6}], {(ka), -0.8, 0.8}, Evaluated -> True]

Mathematica graphics

NB: The Plot[Quiet@Table[...] ...,Evaluated -> True] thing is a dirty trick to force colorization. Perhaps someone could come up with something cleaner.

$\endgroup$
4
  • $\begingroup$ But now, all the plots are the same color. Worse, the standard tricks involving Evaluate, With, or the Evaluated option all bring the discontinuities back, as Chop applied to non-numeric expressions just returns the expressions. I was only able to resolve this by generating the data and using ListPlot. $\endgroup$ Commented Nov 7, 2014 at 13:50
  • $\begingroup$ @MarkMcClure b[k_?NumericQ] := Eigenvalues[H /. ka -> k]; Plot[Quiet@Table[b[ka][[i]], {i, 6}], {(ka), -0.8, 0.8}, Evaluated -> True] $\endgroup$ Commented Nov 7, 2014 at 14:33
  • $\begingroup$ Much faster, in fact! I actually considered that but didn't try it as I figured it would be very slow as Eigenvalues is evaluated with each and every step. Evidently, the list Root objects take longer to evaluate than Eigenvalues, which might very well be evaluated numerically in this context. Looks worth a +1! $\endgroup$ Commented Nov 7, 2014 at 14:43
  • 1
    $\begingroup$ @MarkMcClure Thanks, answer updated. Please see the last paragraph $\endgroup$ Commented Nov 7, 2014 at 14:55

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.