# Puzzled about the behavior of NDSolve (ODE's involving Integrals)

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.

### Edit

Here is the code:

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

sol2 =
NDSolve[
{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}]

• Please provide the code in a form that can be copied directly from the question into Mathematica. – bbgodfrey Aug 12 '17 at 21:03
• Done, sorry & thanks. – Andrea Wilson Aug 12 '17 at 21:47

Note the time constraint in the second option below:

SystemOptions["NDSolveOptions"]
(*
{"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}] //
AbsoluteTiming


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:

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


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.

• 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. – Andrea Wilson Aug 12 '17 at 22:29