I am using a differential equation method for finding the roots of a function. My function is much more complicated but I can illustrate my problem with a trivial example. The problem occurs when roots coincide and change direction. I use a differential equation method. The example equation is
eq = s^2 + 2 a s + 1;
where a is a parameter (0 < a) and I wish to find the roots as the parameter is varied. To form the differential equation I take two derivatives and put them together as follows
deq = {D[eq, s], D[eq, a]} /. s -> s[a];
de = deq[[1]] s'[a] + deq[[2]] == 0
(* 2 s[a]+(2 a+2 s[a]) (s^\[Prime])[a]\[Equal]0 *)
I set up the differential equation so that I can solve with different initial conditions and over different ranges of the parameter a
ClearAll[sol];
sol[ic_, ae_] := s /. First[NDSolve[{de, s[0] == ic}, s, {a, 0, ae}]]
I have initial conditions from
ic = s /. Solve[eq == 0 /. a -> 0]
(* {-\[ImaginaryI],\[ImaginaryI]} *)
First case is fine
a1 = 0.999;
rts = sol[#, a1] & /@ ic;
ParametricPlot[Evaluate[{Re[#[a]], Im[#[a]]} & /@ rts], {a, 0, 0.999}]
Second case attempts to go further
a1 = 2;
rts = sol[#, a1] & /@ ic;
NDSolve gets stuck as it attempts to go "round the corner" at -1. Is there a way to get NDSolve to go round the corner? Can I get both solutions going round the corner and choosing opposite directions? (One solution should go towards the origin the other towards infinity.) Thanks for help and suggestions.