28.01.2013 Views

Solving DDEs in Matlab - Radford University

Solving DDEs in Matlab - Radford University

Solving DDEs in Matlab - Radford University

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

so as to allow transient behavior to die out. The problem is solved easily with<br />

dde23, but we cannot make this plot us<strong>in</strong>g results at the mesh po<strong>in</strong>ts sol.x<br />

alone. This is because they are not equally spaced: If t ∗ appears <strong>in</strong> sol.x so<br />

that we have y(t ∗ ) available <strong>in</strong> sol.y, it is generally not the case that t ∗ − 14<br />

appears <strong>in</strong> sol.x, so we do not have y(t ∗ − 14). However, us<strong>in</strong>g ddeval we can<br />

reproduce the figure easily with<br />

t<strong>in</strong>t = l<strong>in</strong>space(50,300,1000);<br />

y<strong>in</strong>t = ddeval(sol,t<strong>in</strong>t);<br />

ylag = ddeval(sol,t<strong>in</strong>t - 14);<br />

plot(y<strong>in</strong>t,ylag);<br />

We specify 1000 po<strong>in</strong>ts because generally a smooth graph <strong>in</strong> the phase plane<br />

requires a good many. Because ddeval is vectorized and exploits fast built<strong>in</strong><br />

functions, there is no need to be concerned about evaluat<strong>in</strong>g the solution at so<br />

many po<strong>in</strong>ts.<br />

As noted <strong>in</strong> §5, dde23 does not require that the equations actually <strong>in</strong>volve<br />

the delays specified. By specify<strong>in</strong>g an additional, artificial delay that is short,<br />

the way the solution is computed is affected, but the solution and the natural<br />

step size rema<strong>in</strong> the same. <strong>Solv<strong>in</strong>g</strong> the Kermack-McKendrick model with the<br />

option ’Stats’ set ’on’, it is found that the problem is solved <strong>in</strong> 133 successful<br />

steps, with 17 failed attempts and a total of 451 function evaluations. Add<strong>in</strong>g<br />

an artificial delay of 10 −4 by chang<strong>in</strong>g lags to [1, 10, 1e-4] <strong>in</strong>creased the<br />

number of successful steps to 164, the number of failed attempts dropped to<br />

12, and the total number of function evaluations rose to 1027. If the step size<br />

had been restricted to the shortest delay, the <strong>in</strong>tegration would have required<br />

at least 300 × 10 4 steps!<br />

Example 2<br />

A careful solution of the Marchuk immunology model discussed briefly <strong>in</strong> §5<br />

is relatively complicated. It serves to make a number of po<strong>in</strong>ts about how to<br />

use dde23 and illustrates some <strong>in</strong>terest<strong>in</strong>g capabilities. The list<strong>in</strong>g that follows<br />

shows the pert<strong>in</strong>ent details, but it has been abbreviated by delet<strong>in</strong>g the details of<br />

scal<strong>in</strong>g and plott<strong>in</strong>g the solution components, which are standard for <strong>Matlab</strong>.<br />

Also, we do not discuss here some aspects of the computation that were taken<br />

up <strong>in</strong> preced<strong>in</strong>g sections.<br />

The Marchuk problem depends on a parameter h6. Figure 15.8 of [6] presents<br />

plots for two values that we reproduce here. In §6 we list an event function,<br />

marchuke, for locat<strong>in</strong>g where the solution component m(t) has value 0.1. To<br />

communicate to the ddefile the <strong>in</strong>formation it needs to evaluate the <strong>DDEs</strong><br />

properly, we <strong>in</strong>troduce a parameter state that is +1 if m(t) ≤ 0.1 and −1<br />

otherwise. As is common <strong>in</strong> the functions of <strong>Matlab</strong>, parameters can be added<br />

at the end of the list of <strong>in</strong>put variables. When we listed marchuke <strong>in</strong> §6, we<br />

deferred discussion of the <strong>in</strong>put arguments h6 and state. Now we understand<br />

that they are parameters that are be<strong>in</strong>g passed to this function by the solver.<br />

As it happens, they are not actually used by this function, but when parameters<br />

20

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!