# Plotting eigenvalues smoothly

I am trying to plot how the eigenvalues of a matrix change by changing a given a parameter t. Of course the ordering of the eigenvalues does not matter mathematically but it does when I want to make nice plots.

I know that the eigenvalues will change smoothly as a function of this parameter, is there any way to impose this rule on the way eigenvalues are ordered?

Here is a bit of code that plots the eigenvalues as a function of time (I am sorting the values because otherwise I get a lot of jumps):

ham = 1/2*{{0, Ωp, 0}, {Ωp,
2 Δp, Ωs}, {0, Ωs,
2*(Δp - Δs)}};
amp = 100;
t0 = -120.0;
dt = 45;
δ = -999;
δp = -1000.;
σ = 25.3;
mat = ham /. {Ωs ->
amp*Exp[-(t/σ)^2], Ωp ->
amp*Exp[-((t +
dt)/σ)^2], Δp -> δp, \
Δs -> δ}
Plot[{(Sort@{Eigenvalues[mat][],
Eigenvalues[mat][]})[], (Sort@{Eigenvalues[mat][],
Eigenvalues[mat][]})[]}, {t, t0, -t0}, Frame -> True,
Axes -> False]


What I am trying to fix is shown below. The eigenvalue should change smoothly so at the crossing point the red color should follow all the way down. A solution (ok, a dirty hack) I found based on the suggestion by Szabolcs is finding the parameter t for which the distance between the two eigenvalues is the smallest by using NMinimize and reversing the ordering of the functions. However if there are more than one crossing it would have to be done for each crossing individually...

I am still hoping that there is perhaps a more elegant solution. For now I will post my hack version anyway in case it might help someone in a similar situation.

ham = 1/2*{{0, Ωp, 0}, {Ωp,
2 Δp, Ωs}, {0, Ωs,
2*(Δp - Δs)}};
amp = 100;
t0 = -120.0;
dt = 45;
δ = -999;
δp = -1000.;
δ = 25.3;
mat = ham /. {Ωs ->amp*Exp[-(t/σ)^2], Ωp ->amp*Exp[-((t + dt)/σ)^2], Δp -> δp,Δs ->δ}
t2 = t /. NMinimize[(Eigenvalues[mat][] - Eigenvalues[mat][])^2, t][]
Show[
Plot[{(Sort[{Eigenvalues[mat][],
Eigenvalues[mat][]},Less])[], (Sort[{Eigenvalues[mat][],
Eigenvalues[mat][]},Less])[]}, {t, t0, t2}],

Plot[{(Sort[{Eigenvalues[mat][], Eigenvalues[mat][]},
Greater])[], (Sort[{Eigenvalues[mat][],
Eigenvalues[mat][]}, Greater])[]}, {t, t2, -t0}]
]


Here are the results: 