 Numeric Delay Differential Equation Examples - Maple Programming Help

Home : Support : Online Help : Applications and Example Worksheets : Differential Equations : examples/NumericDDEs

Numeric Delay Differential Equation Examples

Numeric solutions for initial value problems with ODE/DAE using dsolve[numeric] can accommodate delay terms for the three main variable step integrators: rkf45, ck45, and rosenbrock. Detailed information on delay differential equations, such as setting of initial values, controlling the storage used to retain the delay data, and use with events can be found on the dsolve[numeric][delay] help page.

Index of Examples

 Harmonic Oscillator Variable Delay Predator-Prey Model Wille and Baker Example Multiple Delays and History

Harmonic Oscillator

 > restart;
 > ddesys := {diff(x__1(t), t, t)+x__1(t-tau__1) = 0, diff(x__2(t), t, t)+x__2(t-tau__2) = 0, x__1(0) = 0, x__2(0) = 0, (D(x__1))(0) = 1, (D(x__2))(0) = 1};
 ${\mathrm{ddesys}}{≔}\left\{\frac{{{ⅆ}}^{{2}}}{{ⅆ}{{t}}^{{2}}}\phantom{\rule[-0.0ex]{0.4em}{0.0ex}}\mathrm{x__1}{}\left({t}\right){+}\mathrm{x__1}{}\left({t}{-}\mathrm{τ__1}\right){=}{0}{,}\frac{{{ⅆ}}^{{2}}}{{ⅆ}{{t}}^{{2}}}\phantom{\rule[-0.0ex]{0.4em}{0.0ex}}\mathrm{x__2}{}\left({t}\right){+}\mathrm{x__2}{}\left({t}{-}\mathrm{τ__2}\right){=}{0}{,}\mathrm{x__1}{}\left({0}\right){=}{0}{,}\mathrm{x__2}{}\left({0}\right){=}{0}{,}{\mathrm{D}}{}\left(\mathrm{x__1}\right){}\left({0}\right){=}{1}{,}{\mathrm{D}}{}\left(\mathrm{x__2}\right){}\left({0}\right){=}{1}\right\}$ (1)
 > dsn := dsolve(eval(ddesys, {tau__1 = 0., tau__2 = .1}), numeric):
 > plots[odeplot](dsn, [[t, x__1(t), color = blue], [t, x__2(t), color = red]], 0 .. 20, labels = [t, ""]); Compare to growth:

 > ddesys := {diff(x__2(t), t, t)+x__2(t-tau__2) = 0, diff(x__1(t), t, t)-tau__1*(diff(x__1(t), t))+x__1(t) = 0, x__1(0) = 0, x__2(0) = 0, (D(x__1))(0) = 1, (D(x__2))(0) = 1};
 ${\mathrm{ddesys}}{≔}\left\{\frac{{{ⅆ}}^{{2}}}{{ⅆ}{{t}}^{{2}}}\phantom{\rule[-0.0ex]{0.4em}{0.0ex}}\mathrm{x__2}{}\left({t}\right){+}\mathrm{x__2}{}\left({t}{-}\mathrm{τ__2}\right){=}{0}{,}\frac{{{ⅆ}}^{{2}}}{{ⅆ}{{t}}^{{2}}}\phantom{\rule[-0.0ex]{0.4em}{0.0ex}}\mathrm{x__1}{}\left({t}\right){-}\mathrm{τ__1}{}\left(\frac{{ⅆ}}{{ⅆ}{t}}\phantom{\rule[-0.0ex]{0.4em}{0.0ex}}\mathrm{x__1}{}\left({t}\right)\right){+}\mathrm{x__1}{}\left({t}\right){=}{0}{,}\mathrm{x__1}{}\left({0}\right){=}{0}{,}\mathrm{x__2}{}\left({0}\right){=}{0}{,}{\mathrm{D}}{}\left(\mathrm{x__1}\right){}\left({0}\right){=}{1}{,}{\mathrm{D}}{}\left(\mathrm{x__2}\right){}\left({0}\right){=}{1}\right\}$ (2)
 > dsn := dsolve(eval(ddesys, {tau__1 = .1, tau__2 = .1}), numeric):
 > plots[odeplot](dsn, [[t, x__1(t), color = blue], [t, x__2(t), color = red]], 0 .. 20, labels = [t, ""]); Variable Delay

For variable delay, the maximum delay time, which is not always trivial to compute, needs to be provided in the call to dsolve:

 > restart;
 > dsys_var := {diff(x(t), t) = -x(t-1/2-(1/2)*exp(-t)), x(0) = 1};
 ${\mathrm{dsys_var}}{≔}\left\{\frac{{ⅆ}}{{ⅆ}{t}}\phantom{\rule[-0.0ex]{0.4em}{0.0ex}}{x}{}\left({t}\right){=}{-}{x}{}\left({t}{-}\frac{{1}}{{2}}{-}\frac{{{ⅇ}}^{{-}{t}}}{{2}}\right){,}{x}{}\left({0}\right){=}{1}\right\}$ (3)
 > max_delay := fsolve(t = 1/2+(1/2)*exp(-t), t);
 ${\mathrm{max_delay}}{≔}{0.7388350311}$ (4)
 > dsn_var := dsolve(dsys_var, numeric, delaymax = .74):
 > plots:-odeplot(dsn_var, 0 .. 5, size = [600, "golden"]); Predator-Prey Model

The following example is adapted from the Hutchinson model, where the delay accommodates differences in resource consumption between young and adult members of a population. The delay parameter tau represents the delay from birth to adulthood of a member of the population.

 > restart;
 > ddesys := {diff(pred(t), t) = 10*pred(t-tau)*prey(t-tau)-(1/2)*pred(t)-(1/10)*pred(t)^2,           diff(prey(t), t) = prey(t)*(1-prey(t))-pred(t)*prey(t), pred(0) = 1,           prey(0) = 1};
 ${\mathrm{ddesys}}{≔}\left\{\frac{{ⅆ}}{{ⅆ}{t}}\phantom{\rule[-0.0ex]{0.4em}{0.0ex}}{\mathrm{pred}}{}\left({t}\right){=}{10}{}{\mathrm{pred}}{}\left({t}{-}{\mathrm{\tau }}\right){}{\mathrm{prey}}{}\left({t}{-}{\mathrm{\tau }}\right){-}\frac{{\mathrm{pred}}{}\left({t}\right)}{{2}}{-}\frac{{{\mathrm{pred}}{}\left({t}\right)}^{{2}}}{{10}}{,}\frac{{ⅆ}}{{ⅆ}{t}}\phantom{\rule[-0.0ex]{0.4em}{0.0ex}}{\mathrm{prey}}{}\left({t}\right){=}{\mathrm{prey}}{}\left({t}\right){}\left({1}{-}{\mathrm{prey}}{}\left({t}\right)\right){-}{\mathrm{pred}}{}\left({t}\right){}{\mathrm{prey}}{}\left({t}\right){,}{\mathrm{pred}}{}\left({0}\right){=}{1}{,}{\mathrm{prey}}{}\left({0}\right){=}{1}\right\}$ (5)
 > dsn := dsolve(eval(ddesys, tau = 0), numeric):
 > plots[odeplot](dsn, [[t, prey(t), color = green], [t, pred(t), color = red]], 0 .. 300, legend = [ prey, pred ], labels = [t,""] ); > dsn := dsolve(eval(ddesys, tau = .25), numeric):
 > plots[odeplot](dsn, [[t, prey(t), color = green], [t, pred(t), color = red]], 0 .. 300, legend = [ prey, pred ], labels = [t,""] ); > dsn := dsolve(eval(ddesys, tau = 5), numeric, maxfun = 0):
 > plots[odeplot](dsn, [[t, prey(t), color = green], [t, pred(t), color = red]], 0 .. 300, legend = [ prey, pred ], labels = [t,""] ); > dsn := dsolve(eval(ddesys, tau = 25), numeric):
 > plots[odeplot](dsn, [[t, prey(t), color = green], [t, pred(t), color = red]], 0 .. 300, legend = [ prey, pred ], labels = [t,""] ); Wille and Baker Example

The following example demonstrates chaotic behavior for a simple first order ODE with delay.

 > restart;
 > dsn := dsolve({diff(y(t), t) = 2*y(t-2)/(1+y(t-2)^9.65)-y(t), y(0) = .5, z(t) = y(t-2)}, numeric):
 > plots[odeplot](dsn, [y(t), z(t)], 2 .. 100, numpoints = 15000); Multiple Delays and History

The following example solves $\frac{ⅆ}{ⅆt}\phantom{\rule[-0.0ex]{0.4em}{0.0ex}}y\left(t\right)$ = $-y\left(t\right)-5y\left(t-1\right)-2y\left(t-2\right)$ with initial condition $y\left(t\right)$ = $\mathrm{sin}\left(t\right)$ for $t<0$.

For delays in Maple, the initial conditions are assumed to be held constant for any times prior to the initial time t0. To handle problems where the history prior to t0 is known, piecewise can be used as follows:

 > restart;
 > ddesys := {diff(y(t), t) = -y(t)-5*piecewise(t-1 < 0, sin(t-1), y(t-1))-2*piecewise(t-2 < 0, sin(t-2), y(t-2)), y(0) = sin(0), z(t) = diff(y(t), t)};
 ${\mathrm{ddesys}}{≔}\left\{\frac{{ⅆ}}{{ⅆ}{t}}\phantom{\rule[-0.0ex]{0.4em}{0.0ex}}{y}{}\left({t}\right){=}{-}{y}{}\left({t}\right){-}{5}{}\left(\left\{\begin{array}{cc}{\mathrm{sin}}{}\left({t}{-}{1}\right)& {t}{<}{1}\\ {y}{}\left({t}{-}{1}\right)& {\mathrm{otherwise}}\end{array}\right\\right){-}{2}{}\left(\left\{\begin{array}{cc}{\mathrm{sin}}{}\left({t}{-}{2}\right)& {t}{<}{2}\\ {y}{}\left({t}{-}{2}\right)& {\mathrm{otherwise}}\end{array}\right\\right){,}{y}{}\left({0}\right){=}{0}{,}{z}{}\left({t}\right){=}\frac{{ⅆ}}{{ⅆ}{t}}\phantom{\rule[-0.0ex]{0.4em}{0.0ex}}{y}{}\left({t}\right)\right\}$ (6)
 > dsn := dsolve(ddesys, numeric):
 > plots[odeplot](dsn, [[t, y(t), color = red], [t, z(t), color = blue]], 0 .. 5, legend = [y, z], labels = [t,""] ); 