This example shows how to use `dde23`

to
solve a system of DDEs with constant delays.

Click `ddex1.m`

or
type `edit ddex1.m`

in a command window to view the
code for this example in an editor.

The differential equations are:

$$\begin{array}{l}{y}_{1}{}^{\prime}(t)={y}_{1}(t-1)\hfill \\ {y}_{2}{}^{\prime}(t)={y}_{1}(t-1)+{y}_{2}(t-0.2)\hfill \\ {y}_{3}{}^{\prime}(t)={y}_{2}(t).\hfill \end{array}$$

The history of this problem is constant:

$$\begin{array}{c}{y}_{1}(t)=1\\ {y}_{2}(t)=1\\ {y}_{3}(t)=1\end{array}$$

for *t* ≤ 0.

Create a new program file in the editor. This file will contain a main function and two local functions.

Define the first-order DDE as a local function.

function dydt = ddex1de(t,y,Z) ylag1 = Z(:,1); ylag2 = Z(:,2); dydt = [ylag1(1); ylag1(1)+ylag2(2); y(2)]; end

Define the solution history as a local function.

function S = ddex1hist(t) S = ones(3,1); end

Define the delays,

*τ*_{1},…,*τ*_{k}in the main function.lags = [1,0.2];

Solve the DDE by calling

`dde23`

in the main function. Pass the DDE function, the delays, the solution history, and interval of integration,`[0,5]`

, as inputs.sol = dde23(@ddex1de,lags,@ddex1hist,[0,5]);

The

`dde23`

function produces a continuous solution over the whole interval of integration [*t*_{0},*t*]._{f}Plot the solution returned by

`dde23`

. Add this code to your main function.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','Location','NorthWest');

Evaluate the solution at 10 equally spaced points over the interval of integration. Then plot the results on the same axes as

`sol.y`

. Add this code to the main function.tint = linspace(0,5,10); Sint = deval(sol,tint) hold on plot(tint,Sint,'o');

Run your program to generate and plot the results.

Was this topic helpful?