# How to plot eigenvalues as a function of parameters in a dynamic module?

I am trying to make a fancy interactive plot that shows how the eigenvalues of a matrix mat change under variation of parameters a and b. The eigenvalues themselves are function of a variable q. I can easily do something like this:

mat = {{b, a*-q^2}, {2, a/2}};
H = mat /. {a -> 1, b -> 0.2}
Plot[Eigenvalues[H], {q, 0, 0.2}]


This gives me the desired yet static plot:

How can I do that interactively, lets say with some sliders? Here is what I tried:

mat = {{b, a*-q^2}, {2, a/2}};
DynamicModule[{a = 1, b = 0.5, H},
Column[{
H = Dynamic[Evaluate[mat]];
H,
Dynamic[Eigenvalues[H]],
Dynamic[Plot[Eigenvalues[H], {q, 0, 3}]],
{"a", Slider[Dynamic@a, {0, 1, 0.01}], Dynamic[a]}, {"b",
Slider[Dynamic@b, {0, 1, 0.01}], Dynamic[b]}
}]
]


The code above works half way, i.e., it makes mat dynamic with regard to the choice of a and b via the sliders. However, the part where I try to calculate the eigenvalues does not work and correspondingly also the plotting fails.

What am I doing wrong here? Any help is greatly appreciated!

• Thanks, Erik

By the way: I know I could calculate the eigenvalues with symbolic a and b outside the dynamic module and then simply plot the resulting polynomials. The actual problem involves a larger matrix, where this is unfortunately no option. See also How to plot several functions without jumping? (multiple eigenvalues of a system as functions of 2 parameters) along these lines.

• 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) Take the tour! 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! – Michael E2 May 16 '16 at 15:56

mat[a_, b_, q_] := {{b, a*-q^2}, {2, a/2}};