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
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};
ddesys≔ⅆ2ⅆt2x__1⁡t+x__1⁡t−τ__1=0,ⅆ2ⅆt2x__2⁡t+x__2⁡t−τ__2=0,x__1⁡0=0,x__2⁡0=0,D⁡x__1⁡0=1,D⁡x__2⁡0=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};
ddesys≔ⅆ2ⅆt2x__2⁡t+x__2⁡t−τ__2=0,ⅆ2ⅆt2x__1⁡t−τ__1⁢ⅆⅆtx__1⁡t+x__1⁡t=0,x__1⁡0=0,x__2⁡0=0,D⁡x__1⁡0=1,D⁡x__2⁡0=1
dsn := dsolve(eval(ddesys, {tau__1 = .1, tau__2 = .1}), numeric):
For variable delay, the maximum delay time, which is not always trivial to compute, needs to be provided in the call to dsolve:
dsys_var := {diff(x(t), t) = -x(t-1/2-(1/2)*exp(-t)), x(0) = 1};
dsys_var≔ⅆⅆtx⁡t=−x⁡t−12−ⅇ−t2,x⁡0=1
max_delay := fsolve(t = 1/2+(1/2)*exp(-t), t);
max_delay≔0.7388350311
dsn_var := dsolve(dsys_var, numeric, delaymax = .74):
plots:-odeplot(dsn_var, 0 .. 5, size = [600, "golden"]);
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.
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};
ddesys≔ⅆⅆtpred⁡t=10⁢pred⁡t−τ⁢prey⁡t−τ−pred⁡t2−pred⁡t210,ⅆⅆtprey⁡t=prey⁡t⁢1−prey⁡t−pred⁡t⁢prey⁡t,pred⁡0=1,prey⁡0=1
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):
dsn := dsolve(eval(ddesys, tau = 5), numeric, maxfun = 0):
dsn := dsolve(eval(ddesys, tau = 25), numeric):
The following example demonstrates chaotic behavior for a simple first order ODE with delay.
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);
The following example solves ⅆⅆty⁡t = −y⁡t−5⁢y⁡t−1−2⁢y⁡t−2 with initial condition y⁡t = sin⁡t 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:
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)};
ddesys≔ⅆⅆty⁡t=−y⁡t−5⁢sin⁡t−1t<1y⁡t−1otherwise−2⁢sin⁡t−2t<2y⁡t−2otherwise,y⁡0=0,z⁡t=ⅆⅆty⁡t
dsn := dsolve(ddesys, numeric):
plots[odeplot](dsn, [[t, y(t), color = red], [t, z(t), color = blue]], 0 .. 5, legend = [y, z], labels = [t,""] );
See Also
dsolve,numeric, dsolve,numeric,delay
Download Help Document