Any idea why NDSolve can easily handle the first of these examples, but not the 2nd? I have a system of ODE's involving integrals without closed-form solutions, and keep getting the 2nd error message. The suggested method takes a very long time.

examples 1 and 2


Here is the code:

sol1 = 
    {z'[v] == 1/v*Integrate[Exp[-t]*(1 - Erf[(z[v] - t)/Sqrt[2]]), {t, 0, ∞}],
     z[1] == 1}, 
    {z}, {v, 1, 5}]

sol2 = 
    {z'[v] == 
       1/v*Integrate[Exp[-(t - v)^2/2]*(1 - Erf[(z[v] - t)/Sqrt[2]]), {t, 0, ∞}], 
     z[1] == 1}, 
    {z}, {v, 1, 5}]
  • $\begingroup$ Please provide the code in a form that can be copied directly from the question into Mathematica. $\endgroup$
    – bbgodfrey
    Aug 12, 2017 at 21:03
  • $\begingroup$ Done, sorry & thanks. $\endgroup$ Aug 12, 2017 at 21:47

1 Answer 1


Note the time constraint in the second option below:

  {"NDSolveOptions" ->
    {"DefaultScanDiscontinuityTimeConstraint" -> 1.,
     "DefaultSolveTimeConstraint" -> 1.}}

For me, I get this for the integral:

Integrate[Exp[-(t - v)^2/2]*(1 - Erf[(z[v] - t)/Sqrt[2]]), {t, 0, Infinity}] //

Mathematica graphics

So the integral takes too long, longer than the "DefaultSolveTimeConstraint". But wait! Notice the integral sign-- the integral cannot be calculated. When it is fed to Solve, Mathematica actually attempts to solve the integral several times:

 z'[v] == 1/v*Integrate[
     Exp[-(t - v)^2/2]*(1 - Erf[(z[v] - t)/Sqrt[2]]), {t, 0, Infinity}], z'[v]] //

Mathematica graphics

So it takes way too long for a time constraint of 1 second. Further, the integral sign means at each step of the NDSolve, the integral is going to be calculated symbolically, which will fail, and then numerically approximated. I'd suggest going straight to NIntegrate as follows:

rhs[z_?NumericQ, v_?NumericQ] := 
  NIntegrate[Exp[-(t - v)^2/2]*(1 - Erf[(z - t)/Sqrt[2]]), {t, 0, Infinity}];
sol2 = NDSolve[{z'[v] == 1/v*rhs[z[v], v], z[1] == 1}, {z}, {v, 1, 5}]
(*  {{z -> InterpolatingFunction[{{1., 5.}}, <>]}}  *)

Addendum: For completeness, let me mention you can use SetSystemOptions to set the time constraint to, say, 100 sec., but that seems inadvisable in this particular case.

One might add that if a symbolic integral can be done, it is probably better to compute it before feeding it to NDSolve.

  • $\begingroup$ Thanks!! I tried NIntegrate more primitively, but was getting large errors (compared to if I called the integral a new variable, provided an ODE for it, and integrated by parts until I got sthg mathematica liked better). This seems more promising. $\endgroup$ Aug 12, 2017 at 22:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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