5
$\begingroup$

I need to solve an integral into an ordinary differential equation like this:

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

Note that now the variable in the integrand is not constant. How can I solve it?

$\endgroup$
  • 3
    $\begingroup$ @MMM in the solution you deleted you have y'[0] == 0, should be y'[1] == 1 then it comes out right. (the integral is zero at x=1 ..) $\endgroup$ – george2079 Dec 29 '16 at 16:28
  • $\begingroup$ @george2079 I didn't get alert for your comment. Thanks $\endgroup$ – zhk Dec 30 '16 at 12:34
9
$\begingroup$

Numerical solution:

solution = 
NDSolve[{D[y[x], x] == x + f0[x], y[0] == 1, f0'[x] == y[x], f0[1] == 0}, y[x], {x, 0, 1}];

Symbolic solution from @rewi (Works only in MMA 11.0 and above.):

sol = -((1 + E^2 + E^(1 - x) - 2 E^(2 - x) - 2 E^x - E^(1 + x))/(1 + E^2));

.

Plot[{Evaluate[y[x] /. solution],sol}, {x, 0, 1}, PlotRange -> All, 
PlotStyle -> {{Red, Thin}, {Blue, Dashed}}, PlotLegends -> {"numeric", "symbolic"}]

enter image description here

$\endgroup$
  • $\begingroup$ I like this straightforward solution with numerics. :) $\endgroup$ – Anton Antonov Dec 29 '16 at 14:57
  • 1
    $\begingroup$ In short: to use NDSolve[] efficiently, reformulate your integro-differential equation as a set of ODEs. $\endgroup$ – J. M. will be back soon Dec 29 '16 at 15:13
  • 1
    $\begingroup$ actually, DSolve gives the analytic result with this form with v10.1 (10.1 does not support @rewi 's integro-differential form) $\endgroup$ – george2079 Dec 29 '16 at 15:54
5
$\begingroup$

Mathematica 11.01

eq = {y'[x] == x + Integrate[y[r], {r, 1, x}], y[0] == 1};
sol = First@DSolve[eq, y, x]

enter image description here

eq /. sol // Simplify
{True, True}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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