| MATLAB® | ![]() |
| On this page… |
|---|
Solver | Description |
|---|---|
Solve initial value problems for delay differential equations with constant delays. | |
Solve initial value problems for delay differential equations with general delays. |
Function | Description |
|---|---|
Evaluate the numerical solution using the output of dde23 or ddesd. |
Use these functions to create, alter, or access an options structure. An options structure contains named properties, the values of which are passed to dde23 or ddesd, thus affecting the solution of the problem.
Function | Description |
|---|---|
Create/alter the DDE options structure. | |
Extract properties from options structure created with ddeset. |
The DDE dde23 solver can solve systems of ordinary differential equations, such as
![]()
where
is the independent variable,
is the dependent variable,
and
represents (derivative of y with respect to t)
. The delays (lags)
are positive constants. The solver ddesd allows delays that depend on
and
.
In an initial value problem, you seek the
solution on an interval
with
. The DDE shows that
depends on
values of the solution at times prior to
. In particular,
depends
on
. Because of this, a solution on
depends on its values for
, i.e., its history
.
Generally, the solution
of an IVP for a system of DDEs has
a jump in its first derivative at the initial point
because the first
derivative of the history function does not satisfy the DDE there.
A discontinuity in any derivative propagates into the future at spacings
of
when the delays are constant,
and in a more complicated way when they are not. For the DDEs solved
by dde23 and ddesd, the solution becomes smoother
as the integration proceeds.
This section describes:
| DDE Solver dde23 | |
| DDE Solver ddesd |
The basic syntax for the two solvers is shown in the function reference pages for dde23 and ddesd.
The function dde23 solves initial value problems for DDEs with constant delays. It integrates a system of first-order differential equations
![]()
on the interval
, with
and given history
for
.
dde23 produces a solution that is continuous
on
. You can use the function deval and the output of dde23 to evaluate the solution at specific points on the interval of integration.
dde23 tracks low-order discontinuities and integrates the differential equations with the explicit Runge-Kutta (2,3) pair and interpolant used by ode23. The Runge-Kutta formulas are implicit for step sizes longer than the delays. When the solution is smooth enough that steps this big are justified, the implicit formulas are evaluated by a predictor-corrector iteration.
The function ddesd solves initial value problems for DDEs with general delays. It integrates a system of first-order differential equations
![]()
on the interval
, with
, where delays
can depend on both
and
. Use the function deval and the output of ddesd to evaluate the solution at specific points on the interval of integration.
ddesd integrates with the classic four-stage, fourth-order explicit Runge-Kutta method, and controls the size of the residual of a natural interpolant. It uses iteration to take steps that are longer than the delays. For further details, see "Solving ODEs and DDEs with Residual Control," L.F. Shampine, Applied Numerical Mathematics, 52 (2005), pp 113-127.
dde23 performs better if it is informed of discontinuities in the history and at known locations. Discontinuities may be specified by event functions. There is a property with which you can specify a solution that is different from the value given by the history function.
Discontinuity | Property | Comments |
|---|---|---|
At the initial value
| Generally the initial value
| |
In the history, i.e., the solution at
| Provide the known locations
| |
State-dependent | dde23 and ddesd use the events function you supply to locate these discontinuities. When the solver finds such a discontinuity, restart the integration to continue. Specify the solution structure for the current integration as the history for the new integration. The solver extends each element of the solution structure after each restart so that the final structure provides the solution for the whole interval of integration. If the new problem involves a change in the solution, use the InitialY property to specify the initial value for the new integration. |
The default integration properties in the DDE solver dde23 are selected to handle common problems. In some cases, you can improve solver performance by overriding these defaults. You do this by supplying dde23 with an options structure that specifies one or more property values.
For example, to change the relative error tolerance of dde23 from the default value of 1e-3 to 1e-4,
Create an options structure using the function ddeset by entering
options = ddeset('RelTol', 1e-4);
Pass the options structure to dde23 as follows:
sol = dde23(ddefun,lags,history,tspan,options)
For a complete description of the available options, see the reference page for ddeset.
Solving the System. This example illustrates the straightforward formulation, computation, and display of the solution of a system of DDEs with constant delays. The history is constant, which is often the case. The differential equations are

The example solves the equations on [0,5] with history

for
.
Note The demo ddex1 contains the complete code for this example. To see the code in an editor, click the example name, or type edit ddex1 at the command line. To run the example type ddex1 at the command line. |
Rewrite the problem as a first-order system. To use dde23, you must rewrite the equations as an equivalent system of first-order differential equations. Do this just as you would when solving IVPs and BVPs for ODEs. However, this example needs no such preparation because it already has the form of a first-order system of equations.
Identify the lags. The delays (lags)
are supplied to dde23 as a vector. For the example we could use
lags = [1,0.2];
In coding the differential equations,
= lags(j).
Code the system of first-order DDEs. Once you represent the equations as a first-order system, and specify lags, you can code the equations as a function that dde23 can use.
This code represents the system in the function, ddex1de.
function dydt = ddex1de(t,y,Z)
ylag1 = Z(:,1);
ylag2 = Z(:,2);
dydt = [ylag1(1)
ylag1(1) + ylag2(2)
y(2) ];
Code the history function. The history function for this example is
function S = ddex1hist(t) S = ones(3,1);
Apply the DDE solver. The example now calls dde23 with the functions ddex1de and ddex1hist.
sol = dde23(@ddex1de,lags,@ddex1hist,[0,5]);
Here the example supplies the interval of integration [0,5] directly. Because the history is constant, we could also call dde23 by
sol = dde23(@ddex1de,lags,ones(3,1),[0,5]);
View the results. Complete the example by displaying the results. dde23 returns the mesh it selects and the solution there as fields in the solution structure sol. Often, these provide a smooth graph.
plot(sol.x,sol.y);
title('An example of Wille'' and Baker');
xlabel('time t');
ylabel('solution y');
legend('y_1','y_2','y_3',2)

Evaluating the Solution.
The method implemented in dde23 produces a continuous solution over the whole interval of integration
. You
can evaluate the approximate solution,
, at any point in
using
the helper function deval and the structure sol returned by dde23.
Sint = deval(sol,tint)
The deval function is vectorized. For a
vector tint, the ith column
of Sint approximates the solution
.
Using the output sol from the previous example, this code evaluates the numerical solution at 100 equally spaced points in the interval [0,5] and plots the result.
tint = linspace(0,5); Sint = deval(sol,tint); plot(tint,Sint);
This example solves a system of two DDEs with state-dependent delay that was used as a test problem by W.H. Enright and H. Hayashi [10] because it has an analytical solution. The differential equations are
![]()
The analytical solution
![]()
is used as the history for
and the equations are solved on [0.1, 5]. The only thing different about solving this example
is that it must be solved with ddesd rather than dde23. This is because the first factor in the second equation
has the form
with a delay that depends on the
second component of the solution. The delay is provided to ddesd with a function like
function d = ddex3delay(t,y) % State dependent delay function for DDEX3 d = exp(1 - y(2));
Note The demo ddex3 contains the complete code for this example. To see the code in an editor, click the example name, or type edit ddex3 at the command line. To run the example type ddex3 at the command line. |
This example solves a cardiovascular model due to J. T. Ottesen [6]. The equations
are integrated over the interval [0,1000]. The situation of interest
is when the peripheral pressure
is reduced exponentially from its value of 1.05
to 0.84 beginning at
= 600.
This is a problem with one delay, a constant history, and three differential equations with fourteen physical parameters. It has a discontinuity in a low order derivative at t = 600.
Note The demo ddex2 contains the complete code for this example. To see the code in an editor, click the example name, or type edit ddex2 at the command line. To run the example type ddex2 at the command line. |
In ddex2, the fourteen physical parameters are set as fields in a structure p that is shared with nested functions. The function ddex2de for evaluating the equations begins with
function dydt = ddex2de(t,y,Z) if t <= 600 p.R = 1.05; else p.R = 0.21 * exp(600-t) + 0.84; end . . .
Jumps Property.
The peripheral pressure
is a continuous function
of
, but it does not have a continuous derivative
at t = 600. The example uses the Jumps property to inform dde23 about the location of
this discontinuity.
opts = ddeset('Jumps',600);
After defining the delay tau and the constant history, the call is
sol = dde23(@ddex2de,tau,history,[0, 1000],opts);
The demo ddex2 plots only the third component, the heart rate, which shows a sharp change at t = 600.
Restarting. The example could have solved this problem by breaking it into two pieces
sol = dde23(@ddex2de,tau,history,[0, 600]); sol = dde23(@ddex2de,tau,sol,[600, 1000]);
The solution structure sol on the interval [0,600] serves as history for restarting the integration at t = 600. In the second call, dde23 extends sol so that on return the solution is available on the whole interval [0,1000]. That is, after this second return,
Sint = deval(sol,[300,900]);
evaluates the solution obtained in the first integration at t = 300, and the solution obtained in the second integration at t = 900.
When discontinuities occur in low order derivatives at points known in advance, it is better to use the Jumps property. This is not an option with ddesd, which handles discontinuities in a different way. When you use event functions to locate such discontinuities, you must restart the integration at discontinuities.

The following additional examples are available. Type
edit examplename
to view the code and
examplename
to run the example.
Example | Description |
|---|---|
Straightforward example | |
Cardiovascular model with discontinuities | |
Problem involving state-dependent delays |
Additional examples are provided by "Tutorial on Solving DDEs with DDE23," available at http://www.mathworks.com/dde_tutorial.
![]() | ODEs | BVPs | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |