Вы находитесь на странице: 1из 25

Delay Differential Equations

Part I: Constant Lags

L.F. Shampine Department of Mathematics Southern Methodist University Dallas, Texas 75275 shampine@smu.edu www.faculty.smu.edu/shampine

Delay Differential Equations


Delay differential equations (DDEs) with constant lags j > 0 for j = 1, . . . , k have the form
y (t) = f (t, y(t), y(t 1 ), . . . , y(t k ))

An early model of the El Nio/Southern Oscillation phenomenon with a physical parameter > 0 is
T (t) = T (t) T (t )

A nonlinear ENSO model with periodic forcing is


h (t) = a tanh[ h(t )] + b cos(2 t)

Analytical Solutions and Stability


Linear, homogeneous, constant-coefcient ODEs have solutions of the form y(t) = et . Any root of the characteristic equation provides a solution. This polynomial equation has a nite number of roots. The characteristic equation for linear, homogeneous, constant-coefcient DDEs is transcendental. Generally there are innitely many roots . Elsgolts and Norkin give asymptotic expressions for these roots. The differential equation is stable if all roots of the characteristic equation satisfy Re() < 0. It is unstable if for some root, Re() > 0.

Example
Substituting y(t) = et into the neutral DDE
y (t) = y (t 1) + y(t) y(t 1)

leads rst to
et = et + et et

and then to the characteristic equation


( 1) 1 e = 0

The roots are 1 and 2i n for integer n.


cos(2nt) and sin(2nt) are solutions for any integer n.

History
An initial value y(a) = (a) is not enough to dene a unique solution of
y (t) = f (t, y(t), y(t 1 ), . . . , y(t k ))

on an interval a t b. We must specify y(t) = (t) for t a so that y(t j ) is dened when a t a + j . The function (t) is called the history of the solution. The Fortran 90 program dde_solver and the two M ATLAB programs allow the history argument to be provided as either a constant vector or a function.

Solving DDEs in M ATLAB


dde23 solves DDEs with constant lags on [a, b].

This is much like solving ODEs with ode23, but


You must input the lags and the history. The end points must satisfy a < b. Output is always in the form of a solution structure. Solution values are available

at mesh points as elds in the structure and anywhere in a t b using deval.

T (t) = T (t) 2 T (t 1)
function Ex1 lags = 1; tspan = [0 6]; sol1 = dde23(@dde,lags,@history,tspan); sol2 = dde23(@dde,lags,1,tspan); tplot = linspace(0,6,100); T1 = deval(sol1,tplot); T2 = deval(sol2,tplot); tplot = [-1 tplot]; T1 = [1 T1]; T2 = [2 T2]; plot(tplot,T1,tplot,T2,0,1,o) %--Subfunctions--------------------function dydt = dde(t,T,Z) dydt = T - 2*Z; function s = history(t) s = 1 - t;

Output of Program
25

20

15

10

10 1

Coding the DDEs


The lag j in f (t, y(t), y(t 1 ), . . . , y(t k )) is dened as component j of an input vector lags.
f is to be evaluated in a function of the form function dydt = ddes(t,y,Z) If there are d equations, y is a d 1 vector that approximates y(t). Z is a d k array. Z(:,j) approximates y(t j ).

ezdde23 is a variant of dde23 with a different syntax for evaluation of the equations: function dydt = ddes(t,y,ylag1,...,ylagk) The d 1 vector ylagj approximates y(t j ).

Method of Steps
For simplicity we discuss the rst-order system
y (t) = f (t, y(t), y(t )), y(t) = (t) for t a

On [a, a + ], this is the ODE


y (t) = f (t, y(t), (t )), y(a) = (a)

With mild assumptions on f there is a unique solution. On [a + , a + 2 ], the term y(t ) in f is known and the initial value y(a + ) is known. Repetition shows the existence, uniqueness, and continuous dependence on the data of a solution for all of [a, b].

Propagation of Discontinuities
Generally the solution y(t) of
y (t) = f (t, y(t), y(t )), y(t) = (t) for t 0

has a jump discontinuity in y (t) at the initial point


t0

lim y (t) = (0) = lim y (t) = f (0, (0), (0 ))


t0+

The initial discontinuity propagates. The second derivative has a jump at , the third derivative has a jump at 2 , etc. Discontinuities increase in order for retarded DDEs, but generally they do not if there are delayed terms involving derivatives, neutral DDEs.

Discontinuity Tree
Because discontinuities in y (m) (t) affect numerical methods greatly, it is important to track them. Multiple lags interact.
0 {1 , 2 } {21 , 1 + 2 , 22 } {31 , 21 + 2 , 1 + 22 , 32 } . . .

Numerical methods do not see discontinuities with m sufciently big, so when solving retarded DDEs, we can cut off branches in the tree of discontinuities. On entry, dde23 works out the tree for its low order RK formulas. It merges values that are close, e.g., lags 2/3 and 2 lead to discontinuities at 2/3 + 2/3 + 2/3 and 2 that are not quite the same.

Special Discontinuities
Hairer, Nrsett, Wanner discuss Marchuks immunology model with
(t) = max(0, 106 + t)

for t 0

They ignore the discontinuity in (t), but dde23 provides for discontinuities in (t). It tracks them into [a, b].
dde23 assumes that y(a) = (a), but sometimes we need a different value for y(a). An example will be discussed later. dde23 provides for y(a) = (a). The jump in y(a) takes longer to smooth out than the usual jump in y (a).

RungeKutta (RK) Formulas


To solve y (t) = f (t, y(t)), start with t0 = a, y0 = (a). Step from yn y(tn ) to yn+1 y(tn+1 ) at tn+1 = tn + hn .
Explicit RK starts with yn,1 = yn , fn,1 = f (tn , yn,1 ) (= yn ). Then for j = 2, 3, . . . , s it forms j1

yn,j = yn + hn
k=1

j,k fn,k ,

fn,j = f (tn + j hn , yn,j )

Finally, yn+1 = yn + hn

s j=1 j fn,j .

If f is smooth enough on [tn , tn+1 ], a formula of order p has y(tn+1 ) = yn+1 + O(hp+1 ). Step to discontinuities so that f is n smooth.

Continuous Extensions
Apply a method for ODEs to y (t) = f (t, y(t), y(t )). Explicit RK deals well with discontinuities, but how do we approximate the solution at arguments that are not mesh points in terms like y(tn + m hn )? Continuous extensions provide values on tn t tn+1 . Cubic Hermite interpolation to yn , yn , yn+1 , yn+1 in ode23 is C 1 [a, b] and preserves order of accuracy.
dde_solver uses yn+ = yn + hn to approximate y(tn + hn ). The stages fn,j are reused, but a few more are needed to preserve the accuracy of higher order formulas. Its continuous extension is C 1 [a, b].
s j ()fn,j j=1

Short Lags
For efciency, we want to use the biggest step size hn that will provide an accurate result. If hn is bigger than a lag j , one of the arguments of y(tn + m hn j ) may be bigger than tn . The term is then not dened and the explicit RK formula is implicit. Some codes limit hn to make the formula explicit, but this can be very inefcient. Predict values for the delayed terms using the continuous extension of the last step. Use them to evaluate the formula and form the continuous extension for the current step. Use it to correct the delayed terms. Iterate as needed.

Solution Structure
A structure (M ATLAB) or derived type (Fortran 90) is used to hold all the information needed to evaluate y(t) anywhere from the initial point a to the current point. In dde23, this is just {tn , yn , yn }. This is used for delayed terms during the integration and on return, for evaluating y(t) with deval. Saaty discusses a model of biological reaction to x-rays that has the form y (t) = ay(t) + b[c y(t )] for 0 t T and the form y (t) = b[c y(t )] for T t. A good way to deal with this is to restart the integration at t = T . By saving the history function (vector), a solution structure can be used as the history argument of dde23. The matter is handled with an auxiliary function in dde_solver.

Rocking Suitcase
A twowheeled suitcase often starts to rock from side to side as it is pulled. You try to return it to the vertical by twisting the handle, but your response is delayed. This is modeled as a second order equation in the angle (t) of the suitcase to the vertical. Write as a rst order system with y1 (t) = (t) and y2 (t) = (t),
y1 (t) = y2 (t) y2 (t) = sin(y1 (t)) sign(y1 (t)) cos(y1 (t)) y1 (t ) + A sin(t + )

The initial history is the constant vector zero.

Nested Function for DDEs


The DDEs are coded in a straightforward way using a global variable state which is sign(y1 (t)). Parameters would be dened in the main program for parameter studies. We could write Z(1) here instead of Z(1,1).
function yp = ddes(t,y,Z) gamma = 0.248; beta = 1; A = 0.75; omega = 1.37; yp = [y(2); 0]; yp(2) = sin(y(1)) - ... state*gamma*cos(y(1))- beta*Z(1,1) + ... A*sin(omega*t + asin(gamma/A)); end % ddes

Event Location
A wheel hits the ground (the suitcase is vertical) when y1 (t) = 0. The integration is then to be restarted with y1 (t) = 0 and y2 (t) multiplied by a coefcient of restitution, here 0.913. The suitcase is considered to have fallen over when |y1 (t)| = /2. Like the ODE solvers, dde23 has event location. This means that during an integration, you can locate solutions of a collection of algebraic equations 0 = gi (t, y, Z) by testing for a change of sign and calculating roots with y(t), y(t 1 ), . . . , y(t k ) evaluated using continuous extensions.

Nested Function for Events


The event function is coded in a straightforward way using the global variable state. When y1 (t) = 0 we change the sign of state and start another integration. Specifying direction allows us to start from this value. isterminal indicates whether the event is to terminate the integration.
function [value,isterminal,direction] = ... events(t,y,Z) value = [y(1); abs(y(1))-pi/2]; isterminal = [1; 1]; direction = [-state; 0]; end % events

Program, Part I
Just like odeset, the function ddeset is used to set options, here events and a more stringent relative error tolerance.
function suitcase state = +1; opts = ddeset(Events,@events, ... RelTol,1e-5); sol = dde23(@ddes,0.1,[0; 0],[0 12],opts); fprintf([Kind of Event:,... time\n]);

Program, Part II
while sol.x(end) < 12 if sol.ie(end) == 1 fprintf([A wheel hit the ground.,... %10.4f\n],sol.x(end)); state = - state; opts = ddeset(opts,InitialY,... [ 0; 0.913*sol.y(2,end)]); sol = dde23(@ddes,0.1,sol,... [sol.x(end) 12],opts); else fprintf([The suitcase fell over.,... %10.4f\n],sol.x(end)); break end end

Program, Part III


Note the eld for y(tn ). With default tolerances a phase plane plot using just mesh points is a little rough. Nested functions must appear in the body of the main function which must end with end. They make it easy to pass global variables like state and parameters.
plot(sol.y(1,:),sol.y(2,:)) xlabel(\theta(t)) ylabel(\theta(t)) axis([-1 2 -1.5 1.2]) % THE NESTED FUNCTIONS APPEAR HERE. end % suitcase

Output
Kind of Event: A wheel hit the ground. A wheel hit the ground. The suitcase fell over.
1

time 4.5168 9.7511 11.6704

0.5

0 (t) 0.5 1 1.5 1

0.5

0.5 (t)

1.5

Вам также может понравиться