0
$\begingroup$

I have seen this error NDSolve::ndsz many times when I use NDSolve to get the solution of a non-autonomous ODE. I try but all failed. Thanks, Here is the code, very simple

 s = NDSolve[{x'[t] == 0.3 y[t], 
       y'[t] == -0.1 x[t] - 0.01 y[t] + 0.2 y[t]^2 + 0.5 Cos[2 Pi t] + 4, 
       x[0] == 1, y[0] == 1}, {x[t], y[t]}, {t, 0, 50 Pi}]

ParametricPlot[Evaluate[{x[t], y[t]} /. s], {t, 0, 50 Pi},  PlotStyle -> Red]
$\endgroup$
8
  • $\begingroup$ ParametricPlot won't show the graph properly. I don't know this way is suitable,the following works: ListPlot[Table[Evaluate[{x[t], y[t]} /. s], {t, 0, 50 Pi}], PlotStyle -> Red] $\endgroup$
    – Xminer
    Jan 17 '19 at 2:11
  • $\begingroup$ NDSolve is very robust for initial value problem (IVP) of ODEs, if it fails on such problem, the equation system itself is probably wrong. Just check: Plot[Evaluate[{x[t], y[t]} /. s], {t, 0, 1.53}, PlotRange -> All] $\endgroup$
    – xzczd
    Jan 17 '19 at 2:17
  • $\begingroup$ @Xminer Your code is not working properly, notice the domain of s is {0., 1.53703}. $\endgroup$
    – xzczd
    Jan 17 '19 at 2:23
  • 1
    $\begingroup$ It's pretty clear that once y[t] > 0 and y[t]^2 > 0.1 x[t] + 0.01 y[t] that a singularity will develop in finite time. To me that doesn't mean the code is wrong. But if there's some reason why the actual problem should not have a singularity, then, yes, the code is not set up right. Here's an easy way to plot the solution: s = NDSolve[{x'[t] == 0.3 y[t], y'[t] == -0.1 x[t] - 0.01 y[t] + 0.2 y[t]^2 + 0.5 Cos[2 Pi t] + 4, x[0] == 1, y[0] == 1}, {x, y}, {t, 0, 50 Pi}]; ListLinePlot[{x, y} /. First@s] $\endgroup$
    – Michael E2
    Jan 17 '19 at 2:38
  • $\begingroup$ Here's an IC without a singularity: s = NDSolve[{x'[t] == 0.3 y[t], y'[t] == -0.1 x[t] - 0.01 y[t] + 0.2 y[t]^2 + 0.5 Cos[2 Pi t] + 4, x[0] == 50, y[0] == -1}, {x, y}, {t, 0, 50 Pi}]; Graphics[{Blue, Thick, Line[ Transpose[{x["ValuesOnGrid"], y["ValuesOnGrid"]} /. First@s]]}, Frame -> True] $\endgroup$
    – Michael E2
    Jan 17 '19 at 2:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.