Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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}]

Mathematica graphics

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.

share|improve this question

It looks like you're trying to draw a root locus -- there is a special command for this:

RootLocusPlot[s^2 + 2 a s + 1, {a, 0, 2}]

enter image description here

share|improve this answer
Thanks.I am familiar with RootLocusPlot[] but my more complicated functions (not always a polynomial) needs a more "personal" touch. It is interesting to note that RootLocusPlot[] does get "round the corner". How does it do that? – Hugh Jun 1 '14 at 17:17
Also, note that RootLocusPlot[] is the Evans Root Locus and assumes that there is a feedback path. If you look at your solution it does not go through the same points as mine. – Hugh Jun 1 '14 at 17:37
You can apply the root locus to a simple polynomial rather than one with a feedback loop (there is an example in the docs). But in any case, it can only handle polynomials -- if you stick a Log or Exp or some nonlinearity, you would need to do it yourself. – bill s Jun 1 '14 at 17:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.