# NDSolve message: Step size changed sign at t == 65.380000

I wanted to solve a nonlinear DDE until a given condition. I got the following error message:

NDSolve::ndssc: Step size changed sign at t == 65.380000.

Does anyone know the solution?

• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! Jan 21, 2018 at 22:31
• People here generally like users to post code as Mathematica code instead of images or TeX, so they can copy-paste it. It makes it convenient for them and more likely you will get someone to help you. You may find this this meta Q&A helpful Jan 21, 2018 at 22:31

NDSolve does not work well for an infinite integration range, perhaps because it uses the range to set the initial step size. Instead, use a large upper bound, for instance, 1000. It also is unnecessary to specify Method and MaxSteps.

ζ = 0.01;
p = 0.010;
q = 0.003;
A = 0.01;
τ = 4.67;
ω = 0.9;

eqn = {x''[t] + 2 ζ x'[t] + x[t] + p (x[t] - x[t - τ]) -
q ((x[t] - x[t - τ])^2 - (x[t] - x[t - τ])^3) == 0, x[t /; t <= 0] == 2,
WhenEvent[x[t] == 100, rMax = t; "StopIntegration"]};
sol = NDSolve[eqn, x, {t, 0, 1000}];
Plot[x[t] /. sol, {t, 0, rMax}, PlotRange -> All, AxesLabel -> {t, x},
ImageSize -> Large, LabelStyle -> Directive[Bold, Black, Medium]]
rMax


(* 166.033 *)

• NDSolve produces an identical solution to yours over the {0, Infinity} domain with MaxStepSize -> 10^1000. In all cases, this one, yours and the OP's, the step size is always much smaller than 1. I can't explain it, and it might be a bug. Jan 22, 2018 at 1:20
• @MichaelE2 Great observation. It does sound like a bug. Was there anything unusual about the step sizes near the time at which the OP's calculation failed? Jan 22, 2018 at 1:24
• Nothing I see: i.sstatic.net/9JasF.png -- the step sizes in your solution are similar, around 0.1 with occasional jumps to small steps. (Probably should've used Log10 instead of RealExponent, but all differences are positive; so there's no difference.) Jan 22, 2018 at 1:32
• @MichaelE2 Nothing I see either just before the calculation fails. However, the rapid decrease in the time step around step 70 is striking, as if the time step was headed toward negative but did not quite make it. Do you plan to report this as a bug? Thanks. Jan 22, 2018 at 1:37
• That decrease is present in your solution, too. Yours has a few others. They are roughly half-machine-precision steps (roughly Sqrt[$MachineEpsilon] * t), which is the rule-of-thumb step for recalibrating the derivative of the RHS in$x'(t) = RHS(x, t)\$ for the error estimator. I've seen this before, and my guess is that NDSolve got an error estimate that was way too big. It might or might not be related to the step-reversal error. Also, I don't know much about DDEs, so I may be oblivious to an obvious issue. Jan 22, 2018 at 1:54