Numpy scipy - store eigenvalues ​​in strict order

I am calculating eigenvalues ​​of a time matrix using scipy.linalg.eigvalsh (matrix) for each point in time. Then I collect them in a nested list ([[result in time 1], [result in time 2], etc.] and save the list via numpy.savetxt.

My problem is that so far I have not been able to find a way how, when I read the results from my file and draw them, I can avoid "mixing" the values. Whenever two eigenvalues ​​(corresponding to energy levels) intersect with each other in time, what happens to my graph is that the line that is being drawn automatically switches. Thus, the lowest energy level, for example, is always displayed as a solid line, although at some point initially the lowest level becomes the second in relation to the lowest and the initial from the second to the lowest (maybe drawn as a dashed line) then this lowest level. Thus, you can see on the graph where the solid line should be the second smallest and the dotted line should be the lowest.but in this case the lines "swap" the style.

My idea to fix the problem was to somehow calculate the slope of the lines and order the elements of the results for each point in time accordingly so that, for example, the first element in each sublist corresponds to what was the lowest eigenvalue initially. But I couldn't find an easy and systematic way to do this, despite looking for similar problems all over the internet, so I really hope someone else can have a similar problem and find some possible solution for it.

+3

source to share

All Articles