Suppose I have a matrix which depends on some parameter. I want to compute the eigenvalues as a function of this parameter, and then plot them. For example, I may have a matrix representing the Hamiltonian of a system in a magnetic field, and I want to plot the energies of the various states as a function of B-field. Sometimes the eigenvalues may cross each other, but I want to make sure the right eigenvalue stays associated with its own state. For example, consider the matrix
H = {{1/2 + 21 B, 0, 0, 0, 0, 0}, {0, 1/2 + 7 B, 0, 0, 7 Sqrt[2] B,
0}, {0, 0, 1/2 - 7 B, 0, 0, 7 Sqrt[2] B}, {0, 0, 0, 1/2 - 21 B, 0,
0}, {0, 7 Sqrt[2] B, 0, 0, -1 + 14 B, 0}, {0, 0, 7 Sqrt[2] B, 0,
0, -1 - 14 B}}
If I evaluate evals = Eigenvalues[H]
and then plot the result, I see a nice plot of the eigenvalues and the states follow properly through crossings, for example just below B = 0.05.
As my matrix gets large, it becomes extremely slow to do the eigendecomposition analytically, so I'd rather do it numerically. However, in this case the eigenvalues don't properly track through crossings-- instead, they are sorted by value from largest to smallest in absolute value. For example, if I do the following
list = {};
Do[
evalsN = Eigenvalues[H];
AppendTo[list, evalsN],
{B, 0, 0.1, 0.001}]
then I get a messed up plot like this:
This is for two reason: (1) because the ordering is all off, and (2) because the states don't track through crossing. I can fix problem (1) by ordering the eigenvalues by their magnitude, but that does NOT help them track through a crossing (e.g., see how the red and purple lines don't cross through one another around element 50). How do I do the second task?
Sort
will work fine if the eigenvalues do not cross. You could also track the derivative of each eigenvalue with respect to your parameter and use that to associate eigenvalues at different values of the parameter (as this will remain nearly constant across a "crossing"). $\endgroup$Sort
will not work due to crossings. In reality, my matrix will be about 48x48 or greater in size, and have many (>10) crossings. $\endgroup$SortBy
the product of the value of an eigenvalue and its derivative with respect to the parameter. That product will remain nearly constant across a "break." $\endgroup$