# NIntegrate into NDSolve with variable integrand

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?

• @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 ..) – george2079 Dec 29 '16 at 16:28
• @george2079 I didn't get alert for your comment. Thanks – zhk Dec 30 '16 at 12:34

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"}]


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

Mathematica 11.01

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


eq /. sol // Simplify
{True, True}