Main Content

dde23

Solve delay differential equations (DDEs) with constant delays

    Description

    sol = dde23(ddefun,delays,history,tspan), where tspan = [t0 tf], integrates the system of delay differential equations y(t)=f(t,y(t),y(tτ1),...,y(tτk)) over the interval specified by tspan, where τ1, ..., τk are constant, positive delays specified by delays.

    example

    sol = dde23(ddefun,delays,history,tspan,options) uses the integration settings defined by options, which is a structure created with the ddeset function. For example, use the AbsTol and RelTol options to specify absolute and relative error tolerances, or the Jumps option to provide locations of discontinuities.

    example

    Examples

    collapse all

    Solve the system of delay differential equations

    y1(t)=-2y1(t-2)+y2(t)y2(t)=y1(t)-2y2(t-1),

    where y1(t) has a constant solution history y1(t)=0.1 and y2(t) has a constant solution history y2(t)=0.5 for t0. The time delay applied to y1(t) is 2 and the time delay applied to y2(t) is 1.

    Define the system of DDEs as a local function named ddefun.

    function dydt = ddefun(t,y,Z)
    ydelay1 = Z(:,1);
    ydelay2 = Z(:,2);
    dydt = [-2*ydelay1(1) + y(2);
            y(1) - 2*ydelay2(2)];
    end

    Specify the interval of integration as [0 10], the time delays as a vector [2; 1], and the solution history as a vector [0.1; 0.5]. Solve the DDE using dde23.

    tspan = [0 10];
    delays = [2; 1];
    history = [0.1; 0.5];
    sol = dde23(@ddefun,delays,history,tspan);

    Plot the results.

    plot(sol.x,sol.y)

    Figure contains an axes object. The axes object contains 2 objects of type line.

    Solve the DDE

    y(t)=-2y(t-1)(1+y(t)),

    where y(t)=t for t0.

    Define the DDE as a local function named ddefun.

    function dydt = ddefun(t,y,ydelay)          
    dydt = -2*ydelay*(1+y);
    end

    Define the solution history as a local function named history.

    function h = history(t)
    h = t;
    end

    Locate the zeros of the equation without terminating the integration by using the ddeset function to specify the Events field of the integrator options structure.

    function [position,isterminal,direction] = zeroEventsFcn(t,y,ydelay)
    position = y(1);
    isterminal = 0;
    direction = 0;
    end
    
    opts = ddeset(Events=@zeroEventsFcn);

    Specify the interval of integration as [0 10] and the time delay as 1. Then solve the DDE using dde23.

    tspan = [0 10];
    delays = 1;
    sol = dde23(@ddefun,delays,@history,tspan,opts);

    Plot the results and the locations of the zero crossings.

    plot(sol.x,sol.y,sol.xe,sol.ye,"o")

    Figure contains an axes object. The axes object contains 2 objects of type line. One or more of the lines displays its values using only markers

    Input Arguments

    collapse all

    System of delay differential equations to solve, specified as a function handle.

    The function dydt = ddefun(t,y,Z) for scalar t and column vector y must return a column vector dydt of data type single or double that corresponds to y(t)=f(t,y(t),y(tτ1),...,y(tτk)). The scalar t corresponds to the current t, the column vector y approximates y(t), and Z(:,j) approximates y(t-τj) for τj = delays(j).

    Example: @myFcn

    Data Types: function_handle

    Time delays, specified as a positive vector. The delays vector represents the constant, positive delays τ1, ..., τk.

    Example: [1 0.2]

    Data Types: single | double

    Solution history at tt0, specified as one of these values:

    • A function handle such that y = history(t) returns a column vector for a scalar t

    • A constant vector y(t)

    • The solution structure sol from a previous integration, if the current dde23 function call continues the integration

    Example: @ddeHist

    Example: [1; 0.4; 0.2]

    Data Types: function_handle | single | double | struct

    Interval of integration, specified as a two-element vector [t0 tf] that represents the initial and final times. To obtain solutions at specific times between t0 and tf, use deval.

    Example: [1 10]

    Data Types: single | double

    Integrator options, specified as a structure array. Use the ddeset function to create or modify the options structure.

    Example: options = ddeset(RelTol=1e-5,Stats="on") specifies a relative error tolerance of 1e-5 and enables the display of solver statistics.

    Data Types: struct

    Output Arguments

    collapse all

    Solution for evaluation, returned as a structure array. Use this structure with the deval function to evaluate the solution at any point in the interval specified by tspan.

    The sol structure includes these fields.

    Structure FieldDescription

    sol.x

    Mesh selected by dde23

    sol.y

    Approximations of y'(x) at the mesh points in sol.x

    sol.yp

    Approximations of y'(x) at the mesh points in sol.x

    sol.solver

    Solver name, 'dde23'

    Additionally, if you specify the Events option in the options structure and events are detected, then sol also includes these fields.

    Structure FieldDescription

    sol.xe

    Points where events occurred. sol.xe(end) contains the exact point of a terminal event, if any.

    sol.ye

    Solutions that correspond to the event time in sol.xe

    sol.ie

    Indices into the vector returned by the function specified in the Events option. The values indicate which event the solver detected.

    Algorithms

    dde23 tracks discontinuities and integrates with the explicit Runge-Kutta (2,3) pair and interpolant of ode23. It uses iteration to take steps longer than the time delays.

    References

    [1] Shampine, Lawrence F., and S. Thompson. "Solving DDEs in MATLAB." Applied Numerical Mathematics 37, no. 4 (June 2001): 441–458. https://doi.org/10.1016/S0168-9274(00)00055-6.

    [2] Kierzenka, Jacek. "Tutorial on Solving DDEs with DDE23." MATLAB Central File Exchange. Updated September 1, 2016. https://www.mathworks.com/matlabcentral/fileexchange/3899-tutorial-on-solving-ddes-with-dde23.

    [3] Willé, David R., and Christopher T. H. Baker. "DELSOL—a Numerical Code for the Solution of Systems of Delay-Differential Equations." Applied Numerical Mathematics 9, no. 3 (April 1992): 223–234. https://doi.org/10.1016/0168-9274(92)90017-8.

    Version History

    Introduced before R2006a