← Back to Math 055

9.2 Runge-Kutta Methods: Class Notes

9.2

A generalization of Euler’s formula is yn+1=yn+h(w1k1+w2k2+⋯+wmkm), where the quantity in parentheses is a weighted average of slopes.

For example, k1 can be the slope y′=f(x,y) at the current point, and k2 can be the predicted slope f(xn+1,yn+1*) from the improved Euler’s method.

Notes: ∑i=1mwi=1, ki are recursively defined, and m is the order of the method.

Definition

For yn+1=yn+hf(xn,yn), we have m=1, w1=1, and k1=f(xn,yn). Thus Euler’s method is a first-order Runge-Kutta method.

For reference: A second-order Runge-Kutta method has the form yn+1=yn+h(w1k1+w2k2), where k1=f(xn,yn) and k2=f(xn+αh,yn+βhk1). When w1+w2=1, w2α=1/2, and w2β=1/2, the results agree with a Taylor polynomial of degree 2. (Note that this is only one choice for the constants; there are others, though we won’t be exploring that.) If we choose w2=1/2, then w1=1/2, and α=β=1. The result agrees with the improved Euler’s method, thus making it a second-order Runge-Kutta method.

A fourth-order Runge-Kutta method (RK4)

An RK4 method uses a weighted average of four slopes to approximate y-values. The basis of the technique is to find parameters so the formula

yn+1=yn+h(w1k1+w2k2+w3k3+w4k4), where

k1=f(xn,yn)k2=f(xn+α1h,yn+β1hk1)k3=f(xn+α2h,yn+β2hk1+β3hk2)k4=f(xn+α3h,yn+β4hk1+β5hk2+β6hk3)

agrees with a 4th-degree Taylor polynomial. The resulting system has 11 equations in 13 unknowns, and common choices for the parameters yields

yn+1=yn+h6(k1+2k2+2k3+k4)k1=f(xn,yn)k2=f(xn+12h,yn+12hk1)k3=f(xn+12h,yn+12hk2)k4=f(xn+h,yn+hk3)

In the general form above, each slope is built from the ones before it: k1 is used in k2, k3, and k4; k2 in k3 and k4; and k3 in k4.

Local and global truncation errors using RK4 are O(h5) and O(h4), respectively.

For comparison: Euler’s method has error O(h), and the improved Euler’s method has error O(h2).

Example

Use the RK4 method to obtain a four-decimal approximation of the indicated value. First use h=0.1 and then use h=0.05.

y′=4x−2y,y(0)=2;y(0.5)

Solution

The work is done in a spreadsheet, one row per step:

RK4 method with h = 0.1
nxnynk1k2k3k4
002−4−3.4−3.46−2.908
10.11.6562−2.9124−2.42116−2.470284−2.0183432
20.21.4109728−2.0219456−1.6197511−1.6599705−1.2899515
30.31.2464505−1.2929009−0.9636109−0.9965399−0.693593
40.41.1480039−0.6960078−0.426407−0.4533671−0.2053344
50.51.1036557

Answer: y(0.5)≈1.1037(h=0.1)

Errors with h = 0.1
xnynActual valueAbs. error% Rel. error
02200%
0.11.65621.65619237.741×10−60.000467%
0.21.41097281.41096011.268×10−50.000898%
0.31.24645051.24643491.557×10−50.001249%
0.41.14800391.14798691.699×10−50.001480%
0.51.10365571.10363831.739×10−50.001576%

At x=0.5 the relative error is 0.001576%, compared with 0.78% for the improved Euler’s method with the same h=0.1 (Section 9.1).

RK4 method with h = 0.05
nxnynk1k2k3k4
002−4−3.7−3.715−3.4285
10.051.8145125−3.429025−3.1575738−3.1711463−2.9119104
20.11.6561927−2.9123854−2.6667661−2.6790471−2.4444807
30.151.5224553−2.4449105−2.222665−2.2337773−2.0215328
40.21.4109609−2.0219217−1.8208256−1.8308805−1.6388337
50.251.3195928−1.6391856−1.4572263−1.4663243−1.2925532
60.31.2464358−1.2928716−1.128228−1.1364602−0.9792256
70.351.1897569−0.9795137−0.830538−0.8379868−0.695715
80.41.1479879−0.6959757−0.561177−0.5679169−0.439184
90.451.11971−0.4394199−0.3174489−0.3235475−0.2070652
100.51.1036393

Answer: y(0.5)≈1.1036(h=0.05)

Errors with h = 0.05
xnynActual valueAbs. error% Rel. error
02200%
0.051.81451251.81451232.459×10−70.000014%
0.11.65619271.65619234.450×10−70.000027%
0.151.52245531.52245476.040×10−70.000040%
0.21.41096091.41096017.286×10−70.000052%
0.251.31959281.3195928.241×10−70.000062%
0.31.24643581.24643498.948×10−70.000072%
0.351.18975691.18975599.446×10−70.000079%
0.41.14798791.14798699.769×10−70.000085%
0.451.119711.1197099.944×10−70.000089%
0.51.10363931.10363839.997×10−70.000091%

Note that h→12h leads to an error about 116 as large: 0.0015760.000091≈17, close to 16. The error is O(h4).