Example 3

We show how to set options and deal with parameters by solving Example 4.2 of [14]. The equation
-ly(t-1) ( 1 + y(t) )
is solved on [0,20] with history y(t) = t for t 0 for four values of the parameter l, namely 1.5, 2, 2.5, and 3.

Often default error tolerances are perfectly satisfactory, but here more stringent tolerances are needed for the larger values of l. Options are set with ddeset exactly as they are set for ode23 with odeset. When options are used, a call to dde23 has the form

   sol = dde23(ddefile,lags,history,tspan,options);
Options like relative and absolute error tolerances are the same in the two solvers. In particular, both have a default relative error tolerance of 10-3 and default absolute error tolerance of 10-6. The tolerances imposed for the larger l in exam3.m are relatively stringent for this solver, but this is a price that must be paid to obtain a satisfactory solution. To see this for yourself, try solving the problem with l = 3 and default tolerances.

Parameters can always be communicated as global variables, but as is common with MATLAB solvers, they can also be passed through dde23 as arguments following the options argument. For two values of l we use default tolerances, so must use an empty array, [], as a placeholder for the options argument. When parameters are passed through dde23, they must appear as arguments of the ddefile and if present, the history function, even if they are not used. Accordingly, exam3f.m can be coded as

   function v = exam3f(t,y,Z,lambda)
   v = -lambda*Z*(1 + y);
and exam3h.m as
   function v = exam3h(t,lambda)
   v = t;

After defining the equation in exam3f.m and the history in exam3h.m, the complete program exam3.m to compute and plot the four solutions as in [14] is

   sol1 = dde23('exam3f',1,'exam3h',[0, 20],[],1.5);

   sol2 = dde23('exam3f',1,'exam3h',[0, 20],[],2);

   opts = ddeset('RelTol',1e-5,'AbsTol',1e-8);
   sol3 = dde23('exam3f',1,'exam3h',[0, 20],opts,2.5);

   opts = ddeset('RelTol',1e-6,'AbsTol',1e-10);
   sol4 = dde23('exam3f',1,'exam3h',[0, 20],opts,3);

   legend('\lambda = 1.5','\lambda = 2.0',...
          '\lambda = 2.5','\lambda = 3.0')
   title('Figure 3. Example 4.2 of Oberle and Pesch.')
This has been coded in a very straightforward manner to make clear that we are solving four problems and using different tolerances.



H.J. Oberle and H.J. Pesch, Numerical treatment of delay differential equations by Hermite interpolation, Numer. Math., 37 (1981) 235-255.