I am using NDSolve
to solving a first order autonomous system of ODEs $\dot x(t) = f(x(t))$, $x\in\mathbb R^n$ numerically for a set of initial conditions $x(0)=a,b,c,…$. I am attempting to solve on the interval {t,0,15}
, but Mathematica will give me
NDSolve::mxst
: Maximum number of 15923184 steps reached at the pointτ == 10.197792214025839`
.
and the obtained solutions would stop at this value of t.
Interesting is also, that this number of maximum steps, and the number of t where it stops depends on the initial value $x(0)$ which I use.
So I am wondering:
(1) How does Mathematica choose this maximum number of steps, and does it have good reasons for it? I suspect that it has to do with oscillations becoming rapid in the solutions with increasing time, but I am not sure. I do not get the warning that the system may have become stiff.
(2) Can I increase this maximum number of solutions?
(3) Is there a specific method, I could dictate NDSolve
to use, which can deal with rapid oscillations for large times better than the default method NDSolve is using?
Thanks for help and insights!
EDIT: Here the corresponding code. It is quite unreadable here on the forum due to all the greek letter. But if you coppy and paste it into a Mathamtica document, it should be nicely readable.
I am using NDSolve
to solving a first order autonomous system of ODEs $\dot x(t) = f(x(t))$, $x\in\mathbb R^n$ numerically for a set of initial conditions $x(0)=a,b,c,…$. I am attempting to solve on the interval {t,0,15}
, but Mathematica will give me
NDSolve: Maximum number of 15923184 steps reached at the point t == 10.198105126672289
.`
and the obtained solutions would stop at this value of t.
Interesting is also, that this number of maximum steps, and the number of t where it stops depends on the initial value $x(0)$ which I use.
So I am wondering:
(1) How does Mathematica choose this maximum number of steps, and does it have good reasons for it? I suspect that it has to do with oscillations becoming rapid in the solutions with increasing time, but I am not sure. I do not get the warning that the system may have become stiff.
(2) Can I increase this maximum number of solutions?
(3) Is there a specific method, I could dictate NDSolve
to use, which can deal with rapid oscillations for large times better than the default method NDSolve is using?
Thanks for help and insights!
EDIT: Here the corresponding code. It is quite unreadable here on the forum due to all the greek letter. But if you coppy and paste it into a Mathamtica document, it should be nicely readable.
(*τ range*)
{τi, τf} = {-40, 40};
τ0 = 0;
(*initial values*)
H0 = .1;
Σ0 = .1;
Ω0 = .9;
φ0 = 0;
t0 = 0;
M0 = 1 - Σ0^2 - Ω0;
sol1 = NDSolve[{
H'[τ] ==
H[τ] (-(1 + 2 Σ[τ]^2 + Ω[τ] (3 Cos[t[τ] - φ[τ]]^2 - 1))),
Σ'[τ] == -(2 - (2 Σ[τ]^2 + Ω[τ] (3 Cos[t[τ] - φ[τ]]^2 -
1))) Σ[τ] + 1 - Σ[τ]^2 - Ω[τ],
Ω'[τ] ==
2 Ω[τ] (1 + (2 Σ[τ]^2 + Ω[τ] (3 Cos[t[τ] - φ[τ]]^2 -
1)) - 3 Cos[t[τ] - φ[τ]]^2),
φ'[τ] == -3 Sin[t[τ] - φ[τ]] Cos[t[τ] - φ[τ]],
M'[τ] ==
2 (2 Σ[τ]^2 + Ω[τ] (3 Cos[t[τ] - φ[τ]]^2 -1) - Σ[τ]) M[τ],
t'[τ] == 1/H[τ],
H[τ0] == H0, Σ[τ0] == Σ0, Ω[τ0] == Ω0, φ[τ0] == φ0,
M[τ0] == M0, t[τ0] == t0},
{H, Σ, Ω, φ, M, t}, {τ, τi, τf}]
MaxSteps->Infinity
. $\endgroup$Differences[Flatten[H["Grid"] /. sol1]][[;; ;; 1000]] // RealExponent // ListPlot
, which plots the log-base-10 of a reasonable sample of the step sizes. $\endgroup$MaxSteps -> Automatic
means a maximum of10000
. For others, it seems to be automatically determined, but always at least10000
. I don't know enough to know why. I can say that the max number of steps in the OP's problem is roughly proportional to the length of the time integrationtf - 0
from the initial condition at0
. It must make an estimate at the beginning of the max steps it would take; if the step size decreases too much over the course of the integration, then it might underestimate what is enough. AFAIK, there's no discussion in the docs. $\endgroup$