68 The Numerical Solution of Differential Equations
We observe that the program first decided that the value of h that we gave it was too big
and it was cut in half. Next we see that the accuracy is pretty good. At x = π we have 3
or 4 correct digits, and we still have them at x =2π. The values of the negative of the sine
function, which are displayed above as the second column of unknowns, are less accurate at
those points. To improve the accuracy we might try reducing the error tolerance eps, but
realistically we will have to confess that the major source of imprecision lies in the Euler
and Trapezoidal combination itself, which, although it provides a good introduction to the
philosophy of these methods, is too crude to yield results of great accuracy over a long range
of integration.
2.11.2 Example: The moon rocket in one dimension
As a second example we will run the moon rocket in one dimension. The equations that
we’re solving now are given by (2.10.19). So all we need to do is to program the right hand
sides f, which we do as follows.
> f:=proc(x,u,j)
> if j=1 then RETURN(u[2]) else RETURN(-1/u[1]^2+.012/(60-u[1])^2) fi:
> end:
Then we invoke our routines by the statement
trapglobal(f,[1,1.4142],.02,0,250,.0001,1000):
This means that we are solving our system with initial data (1,
√
2),withaninitialmeshsize
of h = .02, integrating over the range of time from t =0untilt = 250, with a convergence
tolerance eps of .0001, and printing the output every 1000 lines. We inserted an extra
line of program also, so as to halt the calculation as soon as y[1], the distance from earth,
reached 59.75, which is the surface of the moon.
Maple responded with the following output.
At x= 0 h was reduced to .1000000000e-1
10.00000000, [7.911695068, .5027323920]
20.00000000, [12.36222569, .4022135344]
30.00000000, [16.11311118, .3523608113]
40.00000000, [19.46812426, .3206445364]
50.00000000, [22.55572225, .2979916199]
60.00000000, [25.44558364, .2806820525]
70.00000000, [28.18089771, .2668577906]
80.00000000, [30.79081775, .2554698522]
90.00000000, [33.29624630, .2458746369]
100.0000000, [35.71287575, .2376534139]
110.0000000, [38.05293965, .2305225677]
120.0000000, [40.32630042, .2242857188]
130.0000000, [42.54117736, .2188074327]
140.0000000, [44.70467985, .2139997868]