We now discuss a method for approximating the solution of the initial value problem
that is considerably more accurate than the improved Euler method and is more widely used in practice than any of the numerical methods discussed in Sections 2.4 and 2.5. It is called the Runge–Kutta method, after the German mathematicians who developed it, Carl Runge (1856–1927) and Wilhelm Kutta (1867–1944).
With the usual notation, suppose that we have computed the approximations to the actual values and now want to compute Then
by the fundamental theorem of calculus. Next, Simpson’s rule for numerical integration yields
Hence we want to define so that
we have split into a sum of two terms because we intend to approximate the slope at the midpoint of the interval in two different ways.
On the right-hand side in (4), we replace the [true] slope values and respectively, with the following estimates.
This is the Euler method slope at .
This is an estimate of the slope at the midpoint of the interval using the Euler method to predict the ordinate there.
This is an improved Euler value for the slope at the midpoint.
This is the Euler method slope at using the improved slope at the midpoint to step to .
When these substitutions are made in (4), the result is the iterative formula
The use of this formula to compute the approximations successively constitutes the Runge–Kutta method. Note that Eq. (6) takes the “Euler form”
if we write
for the approximate average slope on the interval .
The Runge–Kutta method is a fourth-order method—it can be proved that the cumulative error on a bounded interval [a, b] with is of order (Thus the iteration in (6) is sometimes called the fourth-order Runge–Kutta method because it is possible to develop Runge–Kutta methods of other orders.) That is,
where the constant C depends on the function f(x, y) and the interval [a, b], but does not depend on the step size h. The following example illustrates this high accuracy in comparison with the lower-order accuracy of our previous numerical methods.
We first apply the Runge–Kutta method to the illustrative initial value problem
that we considered in Fig. 2.4.8 of Section 2.4 and again in Example 2 of Section 2.5. The exact solution of this problem is To make a point we use a larger step size than in any previous example, so only two steps are required to go from to .
In the first step we use the formulas in (5) and (6) to calculate
and then
Similarly, the second step yields .
Figure 2.6.1 presents these results together with the results (from Fig. 2.5.4) of applying the improved Euler method with step size We see that even with the larger step size, the Runge–Kutta method gives (for this problem) four to five times the accuracy (in terms of relative percentage errors) of the improved Euler method.
Improved Euler | Runge–Kutta | ||||
---|---|---|---|---|---|
x | y with | Percent Error | y with | Percent Error | Actual y |
0.0 | 1.0000 | 0.00% | 1.0000 | 0.00% | 1.0000 |
0.5 | 1.7949 | 0.14% | 1.7969 | 0.03% | 1.7974 |
1.0 | 3.4282 | 0.24% | 3.4347 | 0.05% | 3.4366 |
It is customary to measure the computational labor involved in solving numerically by counting the number of evaluations of the function f(x, y) that are required. In Example 1, the Runge–Kutta method required eight evaluations of (four at each step), whereas the improved Euler method required 20 such evaluations (two for each of 10 steps). Thus the Runge–Kutta method gave over four times the accuracy with only 40% of the labor.
Computer programs implementing the Runge–Kutta method are listed in the project material for this section. Figure 2.6.2 shows the results obtained by applying the improved Euler and Runge–Kutta methods to the problem with the same step size The relative error in the improved Euler value at is about 0.24%, but for the Runge–Kutta value it is 0.00012%. In this comparison the Runge–Kutta method is about 2000 times as accurate, but requires only twice as many function evaluations, as the improved Euler method.
The error bound
for the Runge–Kutta method results in a rapid decrease in the magnitude of errors when the step size h is reduced (except for the possibility that very small step sizes may result in unacceptable roundoff errors). It follows from the inequality in (8) that (on a fixed bounded interval) halving the step size decreases the absolute error by a factor of Consequently, the common practice of successively halving the step size until the computed results “stabilize” is particularly effective with the Runge–Kutta method.
x | Improved Euler y | Runge–Kutta y | Actual y |
---|---|---|---|
0.1 | 1.1100 | 1.110342 | 1.110342 |
0.2 | 1.2421 | 1.242805 | 1.242806 |
0.3 | 1.3985 | 1.399717 | 1.399718 |
0.4 | 1.5818 | 1.583648 | 1.583649 |
0.5 | 1.7949 | 1.797441 | 1.797443 |
0.6 | 2.0409 | 2.044236 | 2.044238 |
0.7 | 2.3231 | 2.327503 | 2.327505 |
0.8 | 2.6456 | 2.651079 | 2.651082 |
0.9 | 3.0124 | 3.019203 | 3.019206 |
1.0 | 3.4282 | 3.436559 | 3.436564 |
Infinite discontinuity In Example 5 of Section 2.4 we saw that Euler’s method is not adequate to approximate the solution y(x) of the initial value problem
as x approaches the infinite discontinuity near (see Fig. 2.6.3). Now we apply the Runge–Kutta method to this initial value problem.
Figure 2.6.4 shows Runge–Kutta results on the interval [0.0, 0.9], computed with step sizes and There is still some difficulty near but it seems safe to conclude from these data that .
x | y with | y with | y with |
---|---|---|---|
0.1 | 1.1115 | 1.1115 | 1.1115 |
0.3 | 1.4397 | 1.4397 | 1.4397 |
0.5 | 2.0670 | 2.0670 | 2.0670 |
0.7 | 3.6522 | 3.6529 | 3.6529 |
0.9 | 14.0218 | 14.2712 | 14.3021 |
We therefore begin anew and apply the Runge–Kutta method to the initial value problem
Figure 2.6.5 shows results on the interval [0.5, 0.9], obtained with step sizes and We now conclude that .
Finally, Fig. 2.6.6 shows results on the interval [0.90, 0.95] for the initial value problem
obtained using step sizes and Our final approximate result is The actual value of the solution at is Our slight overestimate results mainly from the fact that the four-place initial value in (12) is (in effect) the result of rounding up the actual value such errors are magnified considerably as we approach the vertical asymptote.
x | y with | y with | y with |
---|---|---|---|
0.5 | 2.0670 | 2.0670 | 2.0670 |
0.6 | 2.6440 | 2.6440 | 2.6440 |
0.7 | 3.6529 | 3.6529 | 3.6529 |
0.8 | 5.8486 | 5.8486 | 5.8486 |
0.9 | 14.3048 | 14.3049 | 14.3049 |
x | y with | y with | y with |
---|---|---|---|
0.90 | 14.3049 | 14.3049 | 14.3049 |
0.91 | 16.7024 | 16.7024 | 16.7024 |
0.92 | 20.0617 | 20.0617 | 20.0617 |
0.93 | 25.1073 | 25.1073 | 25.1073 |
0.94 | 33.5363 | 33.5363 | 33.5363 |
0.95 | 50.4722 | 50.4723 | 50.4723 |
Skydiver A skydiver with a mass of 60 kg jumps from a helicopter hovering at an initial altitude of 5 kilometers. Assume that she falls vertically with initial velocity zero and experiences an upward force of air resistance given in terms of her velocity v (in meters per second) by
(in newtons, and with the coordinate axis directed downward so that during her descent to the ground). If she does not open her parachute, what will be her terminal velocity? How fast will she be falling after 5 s have elapsed? After 10 s? After 20 s?
Newton’s law gives
that is,
because and Thus the velocity function v(t) satisfies the initial value problem
where
The skydiver reaches her terminal velocity when the forces of gravity and air resistance balance, so We can therefore calculate her terminal velocity immediately by solving the equation
Figure 2.6.7 shows the graph of the function f(v) and exhibits the single real solution (found graphically or by using a calculator or computer Solve
procedure). Thus the skydiver’s terminal speed is approximately 35.578 m/s, about 128 km/h (almost 80 mi/h).
t(s) | v(m/s) |
---|---|
0 | 0 |
1 | 9.636 |
2 | 18.386 |
3 | 25.299 |
4 | 29.949 |
5 | 32.678 |
6 | 34.137 |
7 | 34.875 |
8 | 35.239 |
9 | 35.415 |
10 | 35.500 |
11 | 35.541 |
12 | 35.560 |
13 | 35.569 |
14 | 35.574 |
15 | 35.576 |
16 | 35.577 |
17 | 35.578 |
18 | 35.578 |
19 | 35.578 |
20 | 35.578 |
Figure 2.6.8 shows the results of Runge–Kutta approximations to the solution of the initial value problem in (14); the step sizes and yield the same results (to three decimal places). Observe that the terminal velocity is effectively attained in only 15 s. But the skydiver’s velocity is 91.85% of her terminal velocity after only 5 s, and 99.78% after 10 s.
The final example of this section contains a warning: For certain types of initial value problems, the numerical methods we have discussed are not nearly so successful as in the previous examples.
Consider the seemingly innocuous initial value problem
whose exact solution is The table in Fig. 2.6.9 shows the results obtained by applying the Runge–Kutta method on the interval [0, 4] with step sizes and Obviously these attempts are spectacularly unsuccessful. Although as it appears that our numerical approximations are headed toward rather than zero.
x | Runge–Kutta y with | Runge–Kutta y with | Runge–Kutta y with | Actual y |
---|---|---|---|---|
0.4 | 0.66880 | 0.67020 | 0.67031 | 0.67032 |
0.8 | 0.43713 | 0.44833 | 0.44926 | 0.44933 |
1.2 | 0.21099 | 0.29376 | 0.30067 | 0.30119 |
1.6 | 0.14697 | 0.19802 | 0.20190 | |
2.0 | 0.10668 | 0.13534 | ||
2.4 | 0.09072 | |||
2.8 | 0.06081 | |||
3.2 | 0.04076 | |||
3.6 | 0.02732 | |||
4.0 | 0.01832 |
The explanation lies in the fact that the general solution of the equation is
The particular solution of (17) satisfying the initial condition is obtained with But any departure, however small, from the exact solution —even if due only to roundoff error—introduces [in effect] a nonzero value of C in Eq. (18). And as indicated in Fig. 2.6.10, all solution curves of the form in (18) with diverge rapidly away from the one with even if their initial values are close to 1.
Difficulties of the sort illustrated by Example 4 sometimes are unavoidable, but one can at least hope to recognize such a problem when it appears. Approximate values whose order of magnitude varies with changing step size are a common indicator of such instability. These difficulties are discussed in numerical analysis textbooks and are the subject of current research in the field.
A hand-held calculator will suffice for Problems 1 through 10, where an initial value problem and its exact solution are given. Apply the Runge–Kutta method to approximate this solution on the interval [0, 0.5] with step size Construct a table showing five-decimal-place values of the approximate solution and actual solution at the points and 0.5.
Note: The application following this problem set lists illustrative calculator/computer programs that can be used in the remaining problems.
A programmable calculator or a computer will be useful for Problems 11 through 16. In each problem find the exact solution of the given initial value problem. Then apply the Runge–Kutta method twice to approximate (to five decimal places) this solution on the given interval, first with step size then with step size Make a table showing the approximate values and the actual value, together with the percentage error in the more accurate approximation, for x an integral multiple of 0.2. Throughout, primes denote derivatives with respect to x.
0
A computer with a printer is required for Problems 17 through 24. In these initial value problems, use the Runge–Kutta method with step sizes and 0.025 to approximate to six decimal places the values of the solution at five equally spaced points of the given interval. Print the results in tabular form with appropriate headings to make it easy to gauge the effect of varying the step size h. Throughout, primes denote derivatives with respect to x.
Falling parachutist As in Problem 25 of Section 2.5, you bail out of a helicopter and immediately open your parachute, so your downward velocity satisfies the initial value problem
(with t in seconds and v in ft/s). Use the Runge–Kutta method with a programmable calculator or computer to approximate the solution for first with step size and then with rounding off approximate v-values to three decimal places. What percentage of the limiting velocity 20 ft/s has been attained after 1 second? After 2 seconds?
Deer population As in Problem 26 of Section 2.5, suppose the deer population P(t) in a small forest initially numbers 25 and satisfies the logistic equation
(with t in months). Use the Runge–Kutta method with a programmable calculator or computer to approximate the solution for 10 years, first with step size and then with rounding off approximate P-values to four decimal places. What percentage of the limiting population of 75 deer has been attained after 5 years? After 10 years?
Use the Runge–Kutta method with a computer system to find the desired solution values in Problems 27 and 28. Start with step size and then use successively smaller step sizes until successive approximate solution values at agree rounded off to five decimal places.
In Problems 29 and 30, the linear acceleration of a moving particle is given by a formula where the velocity is the derivative of the function giving the position of the particle at time t. Suppose that the velocity v(t) is approximated using the Runge–Kutta method to solve numerically the initial value problem
That is, starting with and the formulas in Eqs. (5) and (6) are applied—with t and v in place of x and y—to calculate the successive approximate velocity values at the successive times (with ). Now suppose that we also want to approximate the distance y(t) traveled by the particle. We can do this by beginning with the initial position and calculating
(), where is the particle’s approximate acceleration at time The formula in (20) would give the correct increment (from to ) if the acceleration remained constant during the time interval .
Thus, once a table of approximate velocities has been calculated, Eq. (20) provides a simple way to calculate a table of corresponding successive positions. This process is illustrated in the project for this section, by beginning with the velocity data in Fig. 2.6.8 (Example 3) and proceeding to follow the skydiver’s position during her descent to the ground.
Consider again the crossbow bolt of Example 2 in Section 2.3, shot straight upward from the ground with an initial velocity of 49 m/s. Because of linear air resistance, its velocity function satisfies the initial value problem
with exact solution (a) Use a calculator or computer implementation of the Runge–Kutta method to approximate v(t) for using both and subintervals. Display the results at intervals of 1 second. Do the two approximations—each rounded to four decimal places—agree both with each other and with the exact solution? (b) Now use the velocity data from part (a) to approximate y(t) for using subintervals. Display the results at intervals of 1 second. Do these approximate position values—each rounded to two decimal places—agree with the exact solution
(c) If the exact solution were unavailable, explain how you could use the Runge–Kutta method to approximate closely the bolt’s times of ascent and descent and the maximum height it attains.
Now consider again the crossbow bolt of Example 3 in Section 2.3. It still is shot straight upward from the ground with an initial velocity of 49 m/s, but because of air resistance proportional to the square of its velocity, its velocity function v(t) satisfies the initial value problem
Beginning with this initial value problem, repeat parts (a) through (c) of Problem 29 (except that you may need subintervals to get four-place accuracy in part (a) and subintervals for two-place accuracy in part (b)). According to the results of Problems 17 and 18 in Section 2.3, the bolt’s velocity and position functions during ascent and descent are given by the following formulas.
Figure 2.6.11 lists TI-Nspire CX CAS and Python programs implementing the Runge–Kutta method to approximate the solution of the initial value problem
considered in Example 1 of this section. The comments provided in the final column should make these programs intelligible even if you have little familiarity with the Python and TI programming languages.
To apply the Runge–Kutta method to a different equation one need only change the initial line of the program, in which the function f is defined. To increase the number of steps (and thereby decrease the step size), one need only change the value of n specified in the second line of the program.
Figure 2.6.12 exhibits a Matlab implementation of the Runge–Kutta method. Suppose that the function f describing the differential equation has been defined. Then the rk
function takes as input the initial value x
, the initial value y
, the final value x1
of x, and the desired number n
of subintervals. As output it produces the resulting column vectors x
and y
of x- and y-values. For instance, the Matlab command
TI-Nspire CX CAS | Python | Comment |
---|---|---|
|
|
|
[X, Y] = rk(0, 1, 1, 10)
then generates the first and third columns of data shown in the table in Fig. 2.6.2.
You should begin this project by implementing the Runge–Kutta method with your own calculator or computer system. Test your program by applying it first to the initial value problem in Example 1, then to some of the problems for this section.
The following problems describe the numbers
as specific values of certain initial value problems. In each case, apply the Runge–Kutta method with subintervals (doubling n each time). How many subintervals are needed to obtain-twice in succession-the correct value of the target number rounded to nine decimal places?
The number where y(x) is the solution of the initial value problem .
The number where y(x) is the solution of the initial value problem .
The number where y(x) is the solution of the initial value problem .
The following Matlab function describes the skydiver’s acceleration function in Example 3.
function vp = f(t,v)
vp = 9.8 - 0.00016*(100*v + 10*v^2 + v^3);
Then the commands
k = 200 % 200 subintervals
[t,v] = rk(0, 0, 20, k); % Runge–Kutta approximation
[t(1:10:k+1); v(1:10:k+1)] % Display every 10th entry
produce the table of approximate velocities shown in Fig. 2.6.8. Finally, the commands
y = zeros(k+1,1): % initialize y
h = 0.1; % step size
for n = 1:k % for n = 1 to k
a = f(t(n),v(n)): % acceleration
y(n+1) = y(n) + v(n)*h +0.5*a*h^2; % Equation (20)
end % end loop
[t(1:20:k+1),v(1:20:k+1),y(1:20:k+1)] % each 20th entry
carry out the position function calculations described in Eq. (20) in the instructions for Problems 29 and 30. The results of these calculations are shown in the table in Fig. 2.6.13. It appears that the skydiver falls 629.866 m during her first 20 s of descent, and then free falls the remaining 4370.134 meters to the ground at her terminal speed of 35.578 m/s. Hence her total time of descent is s, or about 2 min 23 s.
t (s) | v (m/s) | y (m) |
---|---|---|
0 | 0 | 0 |
2 | 18.386 | 18.984 |
4 | 29.949 | 68.825 |
6 | 34.137 | 133.763 |
8 | 35.239 | 203.392 |
10 | 35.500 | 274.192 |
12 | 35.560 | 345.266 |
14 | 35.574 | 416.403 |
16 | 35.577 | 487.555 |
18 | 35.578 | 558.710 |
20 | 35.578 | 629.866 |
For an individual problem to solve after implementing these methods using an available computer system, analyze your own skydive (perhaps from a different height), using your own mass m and a plausible air-resistance force of the form .
18.188.64.66