You may need to reorder on the fly, when roots cross from one of your configurations to another. This happens only where pairs of roots coincide. This in turn happens only when the discriminant vanishes, and this is a polynomial in the parameters.
In[156]:= poly = Array[a, 5, 0].x^Range[0, 4]
(* Out[156]= a[0] + x a[1] + x^2 a[2] + x^3 a[3] + x^4 a[4] *)
In[157]:= disc = Discriminant[poly, x]
(* Out[157]=
a[1]^2 a[2]^2 a[3]^2 - 4 a[0] a[2]^3 a[3]^2 - 4 a[1]^3 a[3]^3 +
18 a[0] a[1] a[2] a[3]^3 - 27 a[0]^2 a[3]^4 - 4 a[1]^2 a[2]^3 a[4] +
16 a[0] a[2]^4 a[4] + 18 a[1]^3 a[2] a[3] a[4] -
80 a[0] a[1] a[2]^2 a[3] a[4] - 6 a[0] a[1]^2 a[3]^2 a[4] +
144 a[0]^2 a[2] a[3]^2 a[4] - 27 a[1]^4 a[4]^2 +
144 a[0] a[1]^2 a[2] a[4]^2 - 128 a[0]^2 a[2]^2 a[4]^2 -
192 a[0]^2 a[1] a[3] a[4]^2 + 256 a[0]^3 a[4]^3 *)
So the condition to check is disc==0
. At such points (in parameter space) pairs of roots can coalesce and you may need to reorder the Root
objects to suit your needs.