Lets say I have the following matrix:

M={{1,3+E^(I x),-1+2I x},{3+E^(-I x),2,E^(3I x)},{-1-2I x,E^(-3I x),-2}};

$$ M=\begin{pmatrix} 1& 3+\mathrm e^{ix} & -1+2ix\\3+\mathrm e^{-ix}&2&\mathrm e^{3ix}\\-1-2ix&\mathrm e^{-3ix}&-2\end{pmatrix} $$

The matrix, being Hermitian, has real eigenvalues. If I plot them, I get the following graph:

Plot[%, {x, -1, 1}]


As you can see, we get discontinuous curves at $x\approx 0.51$, I believe, because of the branch cuts of the roots of the characteristic polynomial (ie, the roots are something like $A(x)\pm B(x)$ and the sign depends on $x$, so the roots change $A(x)+B(x)\to A(x)-B(x)$ at some $x\approx 0.51$). My question is: how can I solve this issue?

Please, consider the following aspects in regard to possible answers:

1) The curves need not be drawn in different colors: they can all be, for example blue.

2) The actual matrix I have is much more complicated that $M$, and it depends on a lot of parameters, so a definite localisation of the discontinuities has to be found at the time of plotting (no exact algebra is possible).

My attepmt

Draw the curves at specific points:

ListPlot[Transpose@Table[%, {x, -1, 1, .05}],PlotStyle->Gray]


This is not really convincing, because Id rather have a continuous curve, as with Plot. Joined->True doesnt help. There has to be a better way.


As @J.M. said, this can be fixed by defining a function:


The problem is, this doesnt work for more complex situations; consider, for example, an extension of the matrix above:

M2={{1,3+E^(I x),-1+2I x,E^(I x)},{3+E^(-I x),2,Exp[3I x],1},{-1-2I x, E^(-3I x),-2,3},{E^(-I x),1,3,4}};

$$ M_2=\begin{pmatrix} 1&1+3\mathrm e^{ix} & -1+2ix & \mathrm e^{ix}\\ 3+\mathrm e^{-ix} &2&\mathrm e^{3ix}&1\\ -1-2ix & \mathrm e^{-3ix}&-2&3\\ \mathrm e^{-ix}&1&3&4\end{pmatrix} $$

so that

Plot[m2[x], {x, -1, 1}]


the same behaviour as before.


Quick fix:

Plot[Sort@m2[x], {x, -1, 1}]

enter image description here

| improve this answer | |
  • $\begingroup$ This does it for all the matrices I tried. Thank you, $\endgroup$ – AccidentalFourierTransform Nov 28 '15 at 0:17

I'm kicking myself for not thinking of ybeltukov's answer, but here's mine. It's another (less efficient) way of sorting, but this has the advantage of preserving colorings.

pts = Table[m2[x], {x, -1., 1, 1/32.}];

  pts[[i]] = MinimalBy[
    Norm[Abs[pts[[i - 1]] - #]] &
  {i, 2, Length[pts]}

ListLinePlot[Transpose[pts], DataRange -> {-1, 1}]

enter image description here

| improve this answer | |

I'm not sure whether this works on more complex situations, but if you just define it as a function, it appears to give what you are looking for:

m[x_] := Eigenvalues[M]
Plot[m[x], {x, -1, 1}]

enter image description here

| improve this answer | |
  • $\begingroup$ Thank you for the answer. I added to the post a different matrix, where defining a function does not fix the problem. $\endgroup$ – AccidentalFourierTransform Nov 27 '15 at 23:36

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.