9

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[0] == 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.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
user7260
  • 91
  • 1
  • 2
  • Mathematica can't directly handle integro-differential equations. Try converting it to an ODE, before feeding it to NDSolve[]. – J. M.'s missing motivation May 04 '13 at 04: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. – Michael E2 Jun 01 '15 at 10:48

2 Answers2

18

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[0] == -(
  LaplaceTransform[y[t], t, s]/(1 + s))
*)

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

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

InverseLaplaceTransform[%, s, t]

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

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

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

Plot[ySolution[t], {t, 0, 10}]

solution

Jens
  • 97,245
  • 7
  • 213
  • 499
6

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[0] == 1,
    f0'[t] == y[t]*Exp[t], f0[0] == 0},
   y[t], {t, 0, 10}];

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

Mathematica graphics

Comparison with Jens's exact solution and how well the combined PrecisionGoal/AccuracyGoal is satisfied:

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

Mathematica graphics

Michael E2
  • 235,386
  • 17
  • 334
  • 747