Main Content

DDE with State-Dependent Delays

This example shows how to use ddesd to solve a system of DDEs (delay differential equations) with state-dependent delays. This system of DDEs was used as a test problem by Enright and Hayashi [1].

The system of equations is



The history functions for t0.1 are the analytical solutions



The time delays in the equations are only present in y terms. The delays depend only on the state of the second component y2(t), so the equations form a system of state-dependent delay equations.

To solve this system of equations in MATLAB®, you need to code the equations, delays, and history before calling the delay differential equation solver ddesd, which is meant for systems with state-dependent delays. You either can include the required functions as local functions at the end of a file (as done here), or save them as separate, named files in a directory on the MATLAB path.

Code Delays

First, write a function to define the time delays in the system. The only delay present in this system of equations is in the term-y2(e1-y2(t)).

function d = dely(t,y)
d = exp(1 - y(2));

Note: All functions are included as local functions at the end of the example.

Code Equation

Now, create a function to code the equations. This function should have the signature dydt = ddefun(t,y,Z), where:

  • t is time (independent variable).

  • y is the solution (dependent variable).

  • Z(n,j) approximates the delays yn(d(j)), where the delay d(j) is given by component j of dely(t,y).

These inputs are automatically passed to the function by the solver, but the variable names determine how you code the equations. In this case:

  • Z(2,1)y2(e1-y2(t))

function dydt = ddefun(t,y,Z)
dydt = [y(2);
       -Z(2,1)*y(2)^2*exp(1 - y(2))];

Code Solution History

Next, create a function to define the solution history. The solution history is the solution for times tt0.

function v = history(t) % history function for t < t0
v = [log(t); 

Solve Equation

Finally, define the interval of integration [t0  tf] and solve the DDE using the ddesd solver.

tspan = [0.1 5];
sol = ddesd(@ddefun, @dely, @history, tspan);

Plot Solution

The solution structure sol has the fields sol.x and sol.y that contain the internal time steps taken by the solver and corresponding solutions at those times. (If you need the solution at specific points, you can use deval to evaluate the solution at the specific points.)

Plot the two solution components against time using the history function to calculate the analytical solution within the integration interval for comparison.

ta = linspace(0.1,5);
ya = history(ta);

legend('y_1 exact','y_2 exact','y_1 ddesd','y_2 ddesd')
xlabel('Time t')
ylabel('Solution y')
title('D1 Problem of Enright and Hayashi')

Local Functions

Listed here are the local helper functions that the DDE solver ddesd calls to calculate the solution. Alternatively, you can save these functions as their own files in a directory on the MATLAB path.

function dydt = ddefun(t,y,Z) % equation being solved
dydt = [y(2); 
       -Z(2,1).*y(2)^2.*exp(1 - y(2))];
function d = dely(t,y) % delay for y
d = exp(1 - y(2));
function v = history(t) % history function for t < t0
v = [log(t); 


[1] Enright, W.H. and H. Hayashi. “The Evaluation of Numerical Software for Delay Differential Equations.” In Proceedings of the IFIP TC2/WG2.5 working conference on Quality of numerical software: assessment and enhancement. (R.F. Boisvert, ed.). London, UK: Chapman & Hall, Ltd., pp. 179-193.

See Also

| | |

Related Topics