I need to use NIntegrate inside NDSolve, for example:

NDSolve[{y'[x] == x + NIntegrate[r, {r, 1, y[x]}], y[2] == 0.5}, y, {x, 0, 1}]

How can I make this work?

  • 5
    $\begingroup$ Why not a. evaluate the integral explicitly; or b. differentiate again so that you have a true ODE instead of an integro-differential equation? $\endgroup$ Jun 7, 2016 at 19:09

1 Answer 1


This may be a perverse way of solving the problem as stated, but as general technique it may be useful. Define an auxiliary function that is only evaluated for numeric arguments, e.g.

f[y_?NumericQ] := NIntegrate[r, {r, 1, y}]

m = NDSolve[{y'[x] == x + f[y[x]], y[2] == 0.5}, y, {x, 0, 1}]
  • $\begingroup$ How should I define coefficients of ODE including NIntegrate if ODE is intended for ParametricNDSolveValue? So far I tried someting like A1N[k_?IntegerQ, bv_?NumericQ, p_?NumericQ] := bva2D1N[k, bv, p]/bva2N[k, bv, p]; where p is free parameter and bv is substituted by bv[z] in final form of ODE for function phi[z]. All functions with names ended by N are some call to NIntegrate. ` $\endgroup$ Sep 3, 2022 at 11:06
  • $\begingroup$ I suggest you ask this as a question where it will be seen by more people. $\endgroup$
    – mikado
    Sep 3, 2022 at 11: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.