340 CHAPTER 9. NUMERICAL METHODS
The dsolve command is applied to sys, subject to the initial condition, a numer-
ical solution being sought with stepsize h. To obtain the Euler approximation,
rather than Maple’s default scheme, the option method=classical[foreuler]
is specified. The output is given as a listprocedure, so that the numerical data
can be extracted for comparison with the first-principles calculation.
>
sol:=dsolve({sys,ic},vars,numeric,stepsize=h,
method=classical[foreuler],output=listprocedure):
The numerical solution, X(t)vs. t, is then plotted over the time interval t=0 to
hn= 60, using the odeplot command. The same number of points is taken as
in the first-principles calculation. The result is shown on the right of Figure 9.1,
a line style having been selected.
>
odeplot(sol,[t,X(t)],0..h*n,axes=normal,style=line,
numpoints=n,labels=["t","x"]);
The two pictures appear to be identical, but we can confirm the agreement
quantitatively by considering a particular time, say, t = 1. The solution sol is
used to evaluate X at arbitrary time t in XX.UsingXX, the dial-up value of x at
t = 1 is given in x1 . The first-principles answer is found by entering pt[100],
the x value at 0.01 × 100 = 1.00 s being the second entry in the output.
>
XX:=eval(X(t),sol): x1:=XX(1); pt[100];
x1 := 1.64892899170276830
[1.00, 1.64892899170276830, −0.0478758403582165596]
The dial-up and first-principles values of x agree to 18 digits!
Because was increased from 5 in our earlier recipe (08-2-1)to20here,the
relaxation oscillations in Figure 9.1 are characterized by even longer periods of
relative inaction between the abrupt temporal changes. It should be mentioned
that an example of a relaxation oscillator in nature (although not governed by
the VdP equation) is the famous geyser Old Faithful in Yellowstone Park.
9.1.2 Survival of the Fittest
The price which society pays for the law of competition ... is great.
But, whether the law be benign or not, ... it is here; we cannot evade
it; no substitutes for it have been found; and while the law may be
sometimes hard for the individual, it is best for the race, because it
ensures the survival of the fittest in every department.
Andrew Carnegie, American industrialist, philanthropist, (1835–1919)
In terms of a Taylor series expansion, the Euler method is of O(h) accurate.
This necessitates taking h very small, which leads to a longer computation time
than for an algorithm which is of higher order accuracy in h, thus permitting a
bigger h to be used. In this recipe, the Volterra–Lotka (V-L) equations will be
solved with the modified Euler method, which is of O(h
2
) accuracy, as well as
with the less accurate Euler method.