Example 1

We illustrate the straightforward solution of a DDE by computing and plotting the solution of Example 3 of [23]. The equations
y1(t-1) + y2(t-0.2)
are to be solved on [0,5] with history y1(t) = 1,y2(t) = 1, y3(t) = 1 for t 0.

A typical invocation of dde23 has the form

   sol = dde23(ddefile,lags,history,tspan);
The input argument tspan is the interval of integration, here [0, 5]. The history argument is the name of a function that evaluates the solution at the input value of t and returns it as a column vector. Here exam1h.m can be coded as
   function v = exam1h(t)
   v = ones(3,1);
Quite often the history is a constant vector. A simpler way to provide the history then is to supply the vector itself as the history argument. The delays are provided as a vector lags, here [1, 0.2]. ddefile is the name of a function for evaluating the DDEs. Here exam1f.m can be coded as
   function v = exam1f(t,y,Z)
   ylag1 = Z(:,1);
   ylag2 = Z(:,2);
   v = zeros(3,1);

   v(1) = ylag1(1);
   v(2) = ylag1(1) + ylag2(2);
   v(3) = y(2);
The input t is the current t and y, an approximation to y(t). The input array Z contains approximations to the solution at all the delayed arguments. Specifically, Z(:,j) approximates y(t-tj) for tj given as lags(j). It is not necessary to define local vectors ylag1, ylag2 as we have done here, but often this makes the coding of the DDEs clearer. The ddefile must return a column vector.

This is perhaps a good place to point out that dde23 does not assume that terms like y(t - tj) actually appear in the equations. Because of this, you can use dde23 to solve ODEs. If you do, it is best to input an empty array, [], for lags because any delay specified affects the computation even when it does not appear in the equations.

The input arguments of dde23 are much like those of ode23, but the output differs formally in that it is one structure, here called sol, rather than several arrays

   [t,y,...] = ode23(...
The field sol.x corresponds to the array t of values of the independent variable returned by ode23 and the field sol.y, to the array y of solution values. So, one way to plot the solution is

After defining the equations in exam1f.m, the complete program exam1.m to compute and plot the solution is

   sol = dde23('exam1f',[1, 0.2],ones(3,1),[0, 5]);

   title('Figure 1. Example 3 of Wille'' and Baker.')
   xlabel('time t');
Note that we must supply the name of the ddefile to the solver, i.e., the string 'exam1f' rather than exam1f. Also, we have taken advantage of the easy way to specify a constant history.



D.R. Willé and C.T.H. Baker, DELSOL - a numerical code for the solution of systems of delay-differential equations, Appl. Numer. Math., 9 (1992) 223-234.