16.12.2012 Views

Computer Algebra Recipes

Computer Algebra Recipes

Computer Algebra Recipes

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

92 CHAPTER 2. PHASE-PLANE ANALYSIS<br />

and beyond the scope of this text. Here, we shall be content to present a few<br />

examples that illustrate some of the more important ideas.<br />

The ¯rst recipe involves revisiting those natural foes, the sly foxes and pesky<br />

jackrabbits of Rainbow County. In this sequel, we will not employ the phaseplane<br />

portrait approach but instead replace each time derivative with a forwarddi®erence<br />

approximation and convert the ODEs to ¯nite di®erence equations.<br />

Recall that the predator{prey equations were of the general structure<br />

_r = ar¡ brf ´ R(r; f ); f _ = ¡cf + drf ´ F (r; f); (2.15)<br />

where r(t) andf(t) aretherabbitandfoxnumbers(perunitarea)attimet.<br />

For the coe±cient values we shall take a =2,b =0:01, c =1,andd =0:01,<br />

and r(0) = 300 rabbits and f(0) = 150 foxes as initial conditions.<br />

To solve this set of ¯rst-order nonlinear ODEs, we can proceed as follows.<br />

If h is the time step size, then the time on step (n + 1) is related to the time<br />

on step n by tn+1 = tn + h. Introducing the notation rn ´ r(tn), fn ´ f(tn),<br />

rn+1 ´ r(tn+1), and fn+1 ´ f(tn+1), the FDA to the two time derivatives is<br />

_r = (rn+1 ¡ rn)<br />

and<br />

h<br />

_ f = (fn+1 ¡ fn)<br />

:<br />

h<br />

The overall accuracy of the numerical scheme then depends on how R(r; f )and<br />

F (r; f ) are approximated. Historically, the oldest and simplest approximation<br />

is to evaluate these functions on the nth time step, reducing the ODEs to<br />

rn+1 = rn + hR(rn;fn); fn+1 = fn + hF(rn;fn): (2.16)<br />

This ¯nite di®erence approximation, which allows one to advance forward a<br />

single step at a time, is referred to as the forward Euler algorithm.<br />

The step size h must be taken to be small to obtain an accurate approximation<br />

to the solution of the original ODEs. How small? A common approach<br />

to answering this question is to cut the step size in two and see what e®ect it<br />

has on the answer. This procedure can be repeated until a su±ciently accurate<br />

answer for your purposes has been attained. Some words of caution should be<br />

o®ered, however. One cannot keep cutting the step size in two inde¯nitely for<br />

a ¯xed number of digits or one will encounter round-o® error, theanswerin<br />

fact becoming less accurate. Further, to execute the worksheet out to the same<br />

total time will take more and more CPU time as the step size is decreased.<br />

Let's now solve equations (2.16), ¯rst loading the plots package and entering<br />

the coe±cient values.<br />

> restart: with(plots):<br />

> a:=2: b:=0.01: c:=1: d:=0.01:<br />

The initial time, initial rabbit number, and initial fox number are speci¯ed and<br />

thetimestepsizetakentobeh =0:02. We take N = 1000 steps, so the total<br />

elapsed time for the numerical run will be 0:02 £ 1000 = 20 time units.<br />

> t[0]:=0: r[0]:=300: f[0]:=150: h:=0.02: N:=1000:<br />

Although the Maple system normally uses 10 digits as its default, the number of<br />

digits is speci¯ed in case it is desired to increase this number, e.g., to lessen the

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

Saved successfully!

Ooh no, something went wrong!