# How to plot and solve the numerical solution of a integro-differential equation

I have a integro-differential equation of the form $y'(t) = - \int_0^t {y(t_1 )} e^{t_1 - t} dt_1, {\rm{ t}} \in {\rm{[0,10], y(0) = 1}}$

My code is:

f[t_Real] := NIntegrate[y[t1]*Exp[t1-t], {t1, 0, t}];

solution1=NDSolve[{D[y[t], t]==-f[t], y == 1}, y[t], {t, 0, 10}];

Plot[Evaluate[y[t] /. solution1], {t, 0, 10}, PlotRange -> All]


But this simply outputs the error:

NIntegrate::nlim: t1 = t is not a valid limit of integration.

• Mathematica can't directly handle integro-differential equations. Try converting it to an ODE, before feeding it to NDSolve[]. May 4 '13 at 4:20
• I fixed some syntax errors in your code. Also I do not get the same error. I get NIntegrate::inumr (because of the symbolic y[t1] in the integral. You probably had a hidden definition f[t_] := NIntegrate[..] that you had not cleared. It's a good idea to restart the kernel and retry your code before posting. Jun 1 '15 at 10:48

This integral equation is solvable using the LaplaceTransform technique:

Clear[s, t];
eqn = y'[t] == -Integrate[y[t1] Exp[t1 - t], {t1, 0, t}]

LaplaceTransform[eqn, t, s]

(*
==>
s LaplaceTransform[y[t], t, s] - y == -(
LaplaceTransform[y[t], t, s]/(1 + s))
*)

Solve[%, LaplaceTransform[y[t], t, s]]

(*
==> {{LaplaceTransform[y[t], t, s] -> ((1 + s) y)/(
1 + s + s^2)}}
*)

InverseLaplaceTransform[%, s, t]

(*
==> {{y[t] -> (
E^(-t/2) (Sqrt Cos[(Sqrt t)/2] + Sin[(Sqrt t)/2]) y)/
Sqrt}}
*)

ySolution[t_] = y[t] /. First[%] /. y -> 1

(*
==> (E^(-t/
2) (Sqrt Cos[(Sqrt t)/2] + Sin[(Sqrt t)/2]))/Sqrt
*)

Plot[ySolution[t], {t, 0, 10}] • Thank you. But I need the numerical solution of the integro-differential equation. May 4 '13 at 5:37
• ...@user, Jens gave you a closed form solution, which is a bit more useful. Why do you still need a numerical solution? Unless... what you posted is in fact not your actual problem. May 4 '13 at 6:23
• Thank you very much! I want to compare the difference the numerical and exact solution of the integro-differential equation. May 4 '13 at 7:15
• @user7260 If you use this package for Laplace inversion, then you can get a semi-numerical solution. Jun 7 '13 at 4:02

This is probably what @Guess who it is. had in mind in the comment posted under the question.

solution1 = NDSolve[{
D[y[t], t] == -Exp[-t] f0[t], y == 1,
f0'[t] == y[t]*Exp[t], f0 == 0},
y[t], {t, 0, 10}];

Plot[Evaluate[y[t] /. solution1], {t, 0, 10}, PlotRange -> All] Comparison with Jens's exact solution and how well the combined PrecisionGoal/AccuracyGoal is satisfied:

jsol = (E^(-t/2) (Sqrt Cos[(Sqrt t)/2] + Sin[(Sqrt t)/2])) / Sqrt;
Plot[Evaluate[{y[t] - jsol /. solution1,
{1, -1} (10^-(MachinePrecision/2.) + 10^-(MachinePrecision/2.) jsol)} // Flatten],
{t, 0, 10}] 