3

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.

Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453
  • Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the [faq]! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Dr. belisarius Nov 06 '14 at 23:46
  • Possible duplicates: http://mathematica.stackexchange.com/questions/51776/how-get-eigenvectors-without-phase-jump http://mathematica.stackexchange.com/questions/39747/how-to-plot-several-functions-without-jumping-multiple-eigenvalues-of-a-system – Szabolcs Nov 07 '14 at 15:26

1 Answers1

3

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.

Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453
  • 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. – Mark McClure Nov 07 '14 at 13:50
  • @MarkMcClure b[k_?NumericQ] := Eigenvalues[H /. ka -> k]; Plot[Quiet@Table[b[ka][[i]], {i, 6}], {(ka), -0.8, 0.8}, Evaluated -> True] – Dr. belisarius Nov 07 '14 at 14:33
  • 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! – Mark McClure Nov 07 '14 at 14:43
  • 1
    @MarkMcClure Thanks, answer updated. Please see the last paragraph – Dr. belisarius Nov 07 '14 at 14:55