# Documentation

### This is machine translation

Translated by
Mouse over text to see original. Click the button below to return to the English verison of the page.

## State-Dependent Delay Problem

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

Click `ddex3.m` or type `edit ddex3.m` in a command window to view the complete code for this example in an editor.

The equations for this system are:

`$\begin{array}{l}{y}_{1}{}^{\prime }\left(t\right)={y}_{2}\left(t\right)\hfill \\ {y}_{2}{}^{\prime }\left(t\right)=-{y}_{2}\left({e}^{\left(1-{y}_{2}\left(t\right)\right)}\right)\cdot {y}_{2}{\left(t\right)}^{2}\cdot {e}^{\left(1-{y}_{2}\left(t\right)\right)}.\hfill \end{array}$`

The analytical solution

`$\begin{array}{l}{y}_{1}\left(t\right)=\mathrm{log}\left(t\right)\hfill \\ {y}_{2}\left(t\right)=1/t\hfill \end{array}$`

is used as the history for t ≤ 0.1 and the equations are solved on `[0.1, 5]` with `ddesd` rather than `dde23`. The `ddesd` function is appropriate in this case because the first factor in the second equation has the form y2(d(y)) with a delay that depends on the second component of the solution.

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

2. Code the system of DDEs as a local function.

```function dydt = ddex3de(t,y,Z) dydt = [y(2); -Z(2)*y(2)^2*exp(1 - y(2))]; end ```
3. Define the delay as a local function.

```function d = ddex3delay(t,y) d = exp(1 - y(2)); end ```
4. Define the solution history as a local function.

```function v = ddex3hist(t) v = [log(t); 1./t]; end```
5. Define the interval of integration and solve the system. Add this code to the main function in your program file.

```tspan = [0.1 5]; sol = ddesd(@ddex3de,@ddex3delay,@ddex3hist,tspan);```
6. Use the history function to calculate the analytical solution within the integration interval. Add this code to the main function.

```texact = linspace(0.1,5); yexact = ddex3hist(texact);```
7. Plot the numerical solution on the same axes as the analytical solution. Add this code to the main function.

```figure plot(texact,yexact,sol.x,sol.y,'o') 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')```
8. Run your program to generate and plot the results.

## References

[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.