it is my first time asking a question here so please let me know if there's anything I should be doing that I'm unaware of. I'm sure the answer to my question already exists on the site but I'm having a hard time understanding what are probably the relevant posts. So here's my question.

In my code I am creating a slightly complicated 4x4 matrix which depends symbolically on multiple variables. I then calculate the eigensystem. Next, for ease of readability and manipulation, I assign the real and imaginary part of each of the 4 eigenvalues into different variables, and then I arrange those variables into lists.

Next I make plots of those lists within manipulate functions so that I can tune the multiple variables on which the initial matrix depends and look at the behavior of the eigenvalues.

The problem which is arising is that the in my plot the lines corresponding to one value will jump back and forth between one line and another line rapidly. I'm pretty sure this is due to the fact that the order of the list for the eigenvalues of eigensystem isn't coming out in the same order every time since a lot of the code is evaluated symbolically.

I am open to suggestions about how to accomplish this. The idea I've come up with is the following: The symbolic expressions resulting from the eigensystem are very complicated and not illuminated and I don't look at them, I am only interested in the plot. To that end, I thought it might make sense to somehow hold the evaluation of much of the initial code until the plot. In other words:

-rather than calculating complicated expressions symbolically and then plugging values for the variables with the plot/manipulate construct the idea would be to:

-within the plot/manipulate construct the code could pick a value for the variables, plug those into the matrix, then calculate the eigensystem, then put the results into a list, and THEN make a plot point for a single set of variables, then move on to the next plot point.

Does this make sense? I realize that one there might be a question of computational efficiency but I'm not sure if the method I'm proposing would be too compuational prohibitive or not so I'd like to give it a try.

I'm pretty sure the way to do this has something to do with the Hold function or evaluation control or something but I haven't been able to put a solution together myself reading the documentation and the existing responses on this website unfortunately. Hopefully the answer is pretty simple!

Here is the code I am looking at.






Here is a picture of the output of one of the graphs so you can see what I'm talking about about the eigenvalue jumping around. I've added different offsets to each eigenvalue so that you can see what is going on with each plot.

enter image description here

Thank you very much for any help with this problem!!

edit: Code updated to -Include variable w -Use the real matrix I am using -pListre and pListim are now defined as pListre[w_,x_,y_,z_] so the code works

The problem I am looking at can be reproduced by using the manipulate to set x to a non-zero value.

  • $\begingroup$ Your code does not produce the plot you showed. In fact, it does not produce any plot at all. You have an extra comma in the definition of Mat, but even removing that no plots are produced. Could you check & fix? $\endgroup$
    – MarcoB
    Apr 17, 2016 at 19:44
  • $\begingroup$ Hello MarcoB. You are correct. The code didn't work properly because I forgot to add in the explicit variable dependencies on pListre and pListim. I have corrected that in the original question. I've also updated the matrix so it is now showing what I am actually trying to compute so that you can reproduce a very similar plot to what I have shown. The same issue will be exhibited. $\endgroup$
    – Jagerber48
    Apr 17, 2016 at 20:27

1 Answer 1


I fixed the issue by utilizing the "Cubics" and "Quartics" options for eigensystem. The code runs much quicker and the manipulates are smoother. There is no more eigenvalues jumping around. Before the output of the eigensystem was a bunch of "root" expressions which I believe remained unevaluted until the plot functions. Now that the expressions are expanded into explicit square root forms I guess they have a fixed order.

{vals[w_, x_, y_, z_], vecs[w_, x_, y_, z_]} = Eigensystem[Mat[w, x, y, z], Cubics -> True, Quartics -> True];
  • $\begingroup$ I suspect the code runs faster because Plot tries to compile the expression before evaluating it, but Root is not a compilable function. By expanding everything in terms of radicals the expression becomes compilable. $\endgroup$
    – QuantumDot
    May 18, 2016 at 13:32

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.