Documentation |
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.mddex3.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}(t)={y}_{2}(t)\hfill \\ {y}_{2}{}^{\prime}(t)=-{y}_{2}({e}^{(1-{y}_{2}(t))})\cdot {y}_{2}{(t)}^{2}\cdot {e}^{(1-{y}_{2}(t))}.\hfill \end{array}$$
The analytical solution
$$\begin{array}{l}{y}_{1}(t)=\mathrm{log}(t)\hfill \\ {y}_{2}(t)=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 y_{2}(d(y)) with a delay that depends on the second component of the solution.
Create a new program file in the editor. This file will contain a main function and three local functions.
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
Define the delay as a local function.
function d = ddex3delay(t,y) d = exp(1 - y(2)); end
Define the solution history as a local function.
function v = ddex3hist(t) v = [log(t); 1./t]; end
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);
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);
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')
Run your program to generate and plot the results.
[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.