An Introductory Example
1.5.2 An Introductory Example
Consider the motion of a ball (or a shot) under the influence of gravity and air resistance. It is well known that the trajectory is a parabola, when the air resistance is neglected and the force of gravity is assumed to be constant. We shall still neglect the variation of the force of gravity as well as the curvature and the rotation of the Earth. This means that we forsake serious applications to, for example, satellites. We shall, however, take the air resistance into account. We neglect the rotation of the shot around its own axis. Therefore, we can treat the problem as motion in a plane, but we have to forsake the application to, for example, table tennis, baseball, or a rotating projectile. Now we have introduced a number of assumptions, which define our model of reality.
The state of the ball is described by its position (x, y) and velocity (u, v), each of which has two Cartesian coordinates in the plane of motion. The x-axis is horizontal, and the y -axis is directed upward. Assume that the air resistance is a force P such that the direction is opposite to the velocity, and the strength z is proportional to the square of the speed and
57 to the square of the radius R of the shot. If we denote by P x and P y the components of P
1.5. Numerical Solution of Differential Equations
along the x and y directions, respectively, we can then write
cR 2
P x = −mzu,
P y = −mzv,
u 2 +v 2 , (1.5.3)
where m is the mass of the ball. For the sake of simplicity we assume that c is a constant. It actually depends on the density and the viscosity of the air. Therefore, we have to forsake the application to cannon shots, where the variation of the density with height is important. If one has access to a good model of the atmosphere, the variation of c would not make the numerical simulation much more difficult. This contrasts with analytic methods, where such a modification is likely to mean a considerable complication. In fact, even with a constant c, a purely analytic treatment offers great difficulties.
Newton’s law of motion tells us that mdu/dt =P x ,
mdv/dt = −mg + P y , (1.5.4) where the term −mg is the force of gravity. Inserting (1.5.3) into (1.5.4) and dividing by m
we get
(1.5.5) and by the definition of velocity,
du/dt = −zu,
dv/dt = −g − zv,
(1.5.6) Equations (1.5.5) and (1.5.6) constitute a system of four differential equations for the four
dx/dt = u,
dy/dt = v.
variables x, y, u, v. The initial state x 0 ,y 0 and u 0 ,v 0 at time t 0 = 0 is assumed to be given.
A fundamental proposition in the theory of differential equations tells us that if initial values of the state variables u, v, x, y are given at some initial time t = t 0 , then they will be
uniquely determined for all t > t 0 .
The simulation of the motion of the ball means that, at a sequence of time instances t n , n = 0, 1, 2, . . . , we determine the approximate values u n ,v n ,x n ,y n . We first look at the simplest technique, using Euler’s method with a constant time step h. Therefore, set t n = nh. We replace the derivative du/dt by the forward difference quotient (u n +1 −u n )/ h , and similarly for the other variables. Hence after multiplication by h, the differential equations are replaced by the following system of difference equations:
x n +1 =x n + hu n , y n +1 =y n + hv n , u n +1 =u n − hz n u n ,
(1.5.7) v n +1 =v n − h(g + z n v n ),
From this x n +1 ,y n +1 ,u n +1 ,v n +1 , etc. are solved, step by step, for n = 0, 1, 2, . . . , using
the provided initial values x 0 ,y 0 ,u 0 , and v 0 .
58 Chapter 1. Principles of Numerical Calculations We performed these computations until y n +1 became negative for the first time, with
g = 9.81, φ = 60 ◦ , and the initial values x 0 = 0, y 0 = 0, u 0 = 100 cos φ, v 0 = 100 sin φ.
Curves obtained for h = 0.01 and cR 2 /m = 0.25i · 10 −3 , i = 0 : 4, are shown in Figure 1.5.2. There is, in this graphical representation, also an error due to the limited
resolution of the plotting device.
Figure 1.5.2. Approximate trajectories computed with Euler’s method with h = 0.01.
In Euler’s method the state variables are locally approximated by linear functions of time, one of the often recurrent ideas in numerical computation. We can use the same idea for computing the coordinate x ∗ of the point where the shot hits the ground. Suppose that y n +1 becomes negative for the first time when n = N. For x N ≤x≤x N +1 we then approximate y by a linear function of x, represented by the secant through the points (x N ,y N ) and (x N +1 ,y N +1 ) , i.e.,
By setting y = 0 we obtain
This is called (linear) inverse interpolation; see Sec. 4.2.2. The error from the linear approximation in (1.5.8) used for the computation of x ∗ is proportional to h 2 . It is thus approximately equal to the error committed in one single step with Euler’s method, and hence of less importance than the other error.
1.5. Numerical Solution of Differential Equations
59 The case without air resistance (i = 0) can be solved exactly. In fact it can be shown
that
9.81 = 5000 · 3/9.81 ≈ 882.7986. The computer produced x ∗ ≈ 883.2985 for h = 0.01, and x ∗ ≈ 883.7984 for h = 0.02.
x ∗ = 2u 0 v 0 /
The error for h = 0.01 is therefore 0.4999, and for h = 0.02 it is 0.9998. The approximate proportionality to h is thus verified, actually more strikingly than could be expected!
It can be shown that the error in the results obtained with Euler’s method is also proportional to h (not h 2 ) . Hence a disadvantage of the above method is that the step length
h must be chosen quite small if reasonable accuracy is desired. In order to improve the method we can apply another idea mentioned previously, namely Richardson extrapolation. (The application differs a little from the one we saw previously, because now the error is approximately proportional to h, while for the trapezoidal rule it was approximately
proportional to h 2 .) For i = 4, the computer produced x ∗ ≈ 500.2646 and x ∗ ≈ 500.3845 for, respectively, h = 0.01 and h = 0.02. Now let x ∗ denote the exact horizontal coordinate
of the landing point. Then x ∗ − 500.2646 ≈ 0.01k,
x ∗ − 500.3845 ≈ 0.02k. By elimination of k we obtain
x ∗ ≈ 2 · 500.2646 − 500.3845 = 500.1447,
which should be a more accurate estimate of the coordinate. By a more accurate integration method we obtained 500.1440. Thus, in this case we gained more than two decimal digits by the use of Richardson extrapolation.
The simulations shown in Figure 1.5.2 required about 1500 time steps for each curve. This may seem satisfactory, but we must not forget that this is a very small task, compared with most serious applications. So we would like to have a method that allows much larger time steps than Euler’s method.