3

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?

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
DeiMos
  • 31
  • 1

1 Answers1

8

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}]
mikado
  • 16,741
  • 2
  • 20
  • 54
  • 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. ` – Igor Kotelnikov Sep 03 '22 at 11:06
  • I suggest you ask this as a question where it will be seen by more people. – mikado Sep 03 '22 at 11:29