5.4 Runge-Kutta Methods

5.4 Runge-Kutta Methods

5.4 Runge-Kutta Methods

The Taylor methods outlined in the previous section have the desirable property of high-order local truncation error, but the disadvantage of requiring the computation and evaluation of the derivatives of . This is a complicated and time-consuming procedure for most problems, so the Taylor methods are seldom used in practice.

Runge-Kutta methods have the high-order local truncation error of the Taylor methods while eliminating the need to compute and evaluate the derivatives of . Before presenting the ideas behind their derivation, we need to state Taylor’s Theorem in two variables. The proof of this result can be found in any standard book on advanced calculus (see, for example, [Fu, p.331]).

Theorem 5.13 Suppose that and all its partial derivatives of order less than or equal to are continuous on , and let. For every , there exists between and and between and with

where

and

The function is called the th Taylor polynomial in two variables for the function about, and is the remainder term associated with.

The first step in deriving a Runge-Kutta method is to determine values for, and with the property that approximates

with error no greater than , the local truncation error for the Taylor method of order two. Since

this implies

(5.18)

Expanding in its Taylor polynomial of degree on about gives

(5.19)

where

(5.20)

for somebetweenand and between and .

Matching the coefficients of and its derivatives in Eqs. (5.18) and (5.19) gives the three equations

and

The parameters are uniquely determined to be

so

and from Eq. (5.20),

If all the second-order partial derivatives of are bounded, then

is , the order of the local truncation error of Taylor method of order two. As a consequence, using the new procedure in place of the Taylor method of order two might add error, but it does not increase the order of the error.

The difference-equation method resulting from replacing in Taylor’s method of order two by is a specific Runge-Kutta method known as the Midpoint method.

Midpoint method:

Since only three parameters are present in and all are needed in the match of , we need a more complicated form to satisfy the condition required for any of the higher-order Taylor methods.

The most appropriate four-parameter form for approximating

is

(5.21)

and even with this, there is insufficient flexibility to match the term

resulting from the expansion of. Consequently, the best that can be obtained from using (5.21) are methods with local truncation error. The fact that (5.21) has four parameters, however, gives a flexibility in their choice, so a number of methods can be derived. One of the most important is the Modified Euler method, which corresponds to choosing and and has the following difference-equation form.

Modified Euler Method:

The other important method is Heun’s method, which correspond to and , and has the following difference-equation form.

Heun’s Method:

Both are classified as Runge-Kutta methods of order two, the order of their local truncation error.

EXAMPLE 2 Suppose we apply the Runge-Kutta methods of order two to our usual example,

with in each case. The difference equations produced from the various formulas are

Midpoint method:

Modified Euler method:

Heun’s method:

for each . Table 5.5 lists the results of these calculations. For this problem, the Midpoint method is superior, followed by Heun’s method.

Table 5.5 (see p277)

Although can be approximated with errorby an expression of the form

involving four parameters, the algebra involved in the determination of is quite involved and will not be presented. In fact, the Runge-Kutta method of order three resulting from this expression is not generally used. The most common Runge-Kutta method in use is of order four and, in difference-equation form, is given by the following.

Runge-Kutta method of Order Four:

for each . This method has local truncation error , provided the solution has five continuous derivatives. The reason for introducing the notation into the method is to eliminate the need for successive nesting in the second variable of (see Exercise 17). Algorithm 5.2 implements the Runge-Kutta method of order four.

Runge-Kutta (Oreder Four)

PURPOSE To approximate the solution of the initial-value problem

at equally spaced numbers in the interval :

INPUT endpoints ; integer ; initial condition ,

OUTPUT approximation to at the values of .

Step 1 ;

;

;

OUTPUT.

Step 2 For do Steps 3-5.

Step 3 ;

;

;

.

Step 4 ; (Compute.)

. (compute.)

Step 5 OUTPUT.

Step6 STOP

This produced Runge-Kutta method of order four (Algorithm 5.2) described in the following subroutine:

SUBROUTINE RK4(N,A,B,ALPHA,T,W)

C******************************************************************

C ALGORITHM 5.2 RUNGE-KUTTA (ORDER 4)

C PURPOSE: TO APPROXIMATE THE SOLUTION TO THE INITIAL VALUE PROBLEM

C Y' = F(T,Y), A <= T <= B, Y(A) = ALPHA,

C AT (N+1) EQUALLY SPACED NUMBERS IN THE INTERVAL [A,B].

C

C INPUT: ENDPOINTS A,B; INITIAL CONDITION ALPHA; INTEGER N.

C

C OUTPUT: APPROXIMATION W TO Y AT THE (N+1) VALUES OF T.

C------

C

INTEGER N

REAL A,B,ALPHA

REAL T(0:10),W(0:10)

REAL XK1,XK2,XK3,XK4,H

INTEGER I

EXTERNAL F

C STEP 1

H = (B-A)/N

T(0)=A

W(0)=ALPHA

C STEP 2

DO 110 I=0,N-1

C STEP 3

C USE XK1,XK2,XK3,XK4 FOR K(1),K(2),K(3),K(4) RESP.

XK1 = H*F(T(I),W(I))

XK2 = H*F(T(I)+H/2,W(I)+XK1/2)

XK3 = H*F(T(I)+H/2,W(I)+XK2/2)

XK4 = H*F(T(I)+H,W(I)+XK3)

C STEP 4

C COMPUTE W(I+1)

W(I+1) = W(I) + (XK1+2*(XK2+XK3)+XK4)/6

C COMPUTE T(I+1)

T(I+1)=A+(I+1)*H

C STEP 5

110 CONTINUE

C STEP 6

RETURN

END

EXAMPLE 3 (Section 5.4, p278) Using the Runge-Kutta method of order four to obtain approximations to the solution of the initial-value problem

with .

AL52.f is shown as follows:

C******************************************************************

C Example 3 (Section 5.4) Using RUNGE-KUTTA (ORDER 4) to

C approximate the solution of the initial-value problem

C dy/dt=y-t^2+1, y(0)=0.5

C******************************************************************

C

INTEGER N

REAL A,B,ALPHA

REAL T(0:10),W(0:10),Y(0:10)

INTRINSIC EXP,ABS

OPEN(UNIT=10,FILE='AL52.doc',STATUS='UNKNOWN')

C *** Input initial values

A = 0.0

B = 2.0

ALPHA = 0.5

N = 10

WRITE(10,*) ' T(i) W(i) Y(i) |W(i)-Y(i)|'

WRITE(10,*) '------'

WRITE(*,*) ' T(i) W(i) Y(i) |W(i)-Y(i)|'

WRITE(*,*) '------'

CALL RK4(N,A,B,ALPHA,T,W)

DO 10 I = 0,10

C *** Exact solution

Y(I) = (T(I)+1.0)*(T(I)+1.0)-0.5*EXP(T(I))

WRITE(10,99) T(I),W(I),Y(I),ABS(W(I)-Y(I))

WRITE(*,99) T(I),W(I),Y(I),ABS(W(I)-Y(I))

10 CONTINUE

STOP

99 FORMAT(1X,F5.1,3F12.7)

END

REAL FUNCTION F(T,Y)

C======

C PURPOSE

C Find the value of function f(t,y) = y-t^2+1

C------

C

REAL T,Y

F = Y-T*T+1.0

RETURN

END

gives the results and errors listed in Table 5.6. ■

Table 5.6

/ Exact
/ Runge-Kutta
Order Four
/ Error

0.0 / 0.5000000 / 0.5000000 / 0
0.2 / 0.8292986 / 0.8292933 / 0.0000053
0.4 / 1.2140877 / 1.2140762 / 0.0000114
0.6 / 1.6489406 / 1.6489220 / 0.0000186
0.8 / 2.1272295 / 2.1272027 / 0.0000269
1.0 / 2.6408591 / 2.6408227 / 0.0000364
1.2 / 3.1799415 / 3.1798942 / 0.0000474
1.4 / 3.7324000 / 3.7323401 / 0.0000599
1.6 / 4.2834838 / 4.2834095 / 0.0000743
1.8 / 4.8151763 / 4.8150857 / 0.0000906
2.0 / 5.3054720 / 5.3053630 / 0.0001089

The main computation effort in applying the Runge-Kutta methods is the evaluation of. In the second-order methods, the local truncation error is , and the cost is two functional evaluation per step. The Runge-Kutta method of order four requires 4 evaluations per step, and the local truncation error is . Butcher (see [But] for a summary) has established the relationship between the number of evaluations per step and the order of the local truncation error shown in Table 5.7. This table indicates why the methods of order less than five with smaller step size are used in preference to the higher-order methods using a larger step size.

Table 5.7

Evaluations per step / 2 3 4
Best possible local
Truncation error /

One measure of comparing the lower-order Runge-Kutta methods is described as follows:

The Runge-Kutta method of order four requires four evaluations per step, so it should give more accurate answers than Euler’s method with one-fourth the step size if it is to be superior. Similarly, if the Runge-Kutta method of order four is to be superior to the second-order Runge-Kutta methods, it should give more accuracy with step size than a second-order method with step size ,because the fourth-order method requires twice as many evaluations per step.

An illustration of the superiority of the Runge-Kutta fourth-order method by this measure is shown in the following example.

EXAMPLE 4 For the problem

Euler’s method with , the Midpoint method with , and the Runge-Kutta fourth-order method with are compared at the common mesh points of these methods 0.1, 0.2, 0.3, 0.4, and 0.5. Each of these techniques requires 20 functional evaluations to determine the values listed in Table 5.8 to approximate . In this example, the fourth-order method is clearly superior. ■

Table 5.8

/ Exact / Euler
/ Modified
Euler
/ Runge-Kutta
Order Four

0.0 / 0.5000000 / 0.5000000 / 0.5000000 / 0.5000000
0.1 / 0.6574145 / 0.6554982 / 0.6573085 / 0.6574144
0.2 / 0.8292986 / 0.8253385 / 0.8290778 / 0.8292983
0.3 / 1.0150706 / 1.0089334 / 1.0147254 / 1.0150701
0.4 / 1.2140877 / 1.2056345 / 1.2136079 / 1.2140869
0.5 / 1.4256394 / 1.4147264 / 1.4250141 / 1.4256384

Extercise set 5.4

Q4. Use the Modified Euler method to approximation the solutions to each if the following initial-value problems, give Fortran code and compare the results to the exact solutions:

Q11. Repeat Q4 using the Runge-Kutta method of order four.

1