Lecture Notes

2.6 Runge-Kutta Method

Processed February 25, 2026 at 09:53 AM
Original Handwritten Notes
PAGE 1

2.6 Runge-Kutta Method

huge family of methods

we will look at Runge-Kutta order 4 method.

\[ y_{n+1} = y_n + \frac{1}{6}(k_1 + 2k_2 + 2k_3 + k_4)h \]
  • \( k_1 = f(t_n, y_n) \) — slope at start (Euler)
  • \( k_2 = f(t_n + \frac{1}{2}h, y_n + \frac{1}{2}k_1 h) \) — slope at mid pt using \( k_1 \) to get there
  • \( k_3 = f(t_n + \frac{1}{2}h, y_n + \frac{1}{2}k_2 h) \) — slope at mid pt using \( k_2 \) to get there
  • \( k_4 = f(t_n + h, y_n + k_3 h) \) — slope at end using \( k_3 \) to get there

\( \frac{1}{6}(k_1 + 2k_2 + 2k_3 + k_4) \) is weighted avg. of the slopes
(more weight to middle)

PAGE 2
A coordinate graph illustrating the Runge-Kutta 4th order (RK4) numerical method. The horizontal axis represents time \(t\) with marked points \(t_0\), \(t_0 + h/2\), and \(t_0 + h\). The vertical axis represents \(y\) with marked points \(y_0\), \(y_0 + hk_1/2\), \(y_0 + hk_2/2\), and \(y_0 + hk_3\). A blue curve labeled \(y(t)\) represents the exact solution. Four red vectors, labeled \(k_1, k_2, k_3,\) and \(k_4\), represent the slopes used in the method. Vector \(k_1\) starts at \((t_0, y_0)\). Vectors \(k_2\) and \(k_3\) are evaluated at the midpoint \(t_0 + h/2\). Vector \(k_4\) is evaluated at the end of the interval \(t_0 + h\). A final point is labeled \((t_1, y_1)\) near the end of the interval on the blue curve.
Figure: A coordinate graph illustrating the Runge-Kutta 4th order (RK4) numerical method. The horizontal axis represents time \(t\) with marked points \(t_0\), \(t_0 + h/2\), and \(t_0 + h\). The vertical axis represents \(y\) with marked points \(y_0\), \(y_0 + hk_1/2\), \(y_0 + hk_2/2\), and \(y_0 + hk_3\). A blue curve labeled \(y(t)\) represents the exact solution. Four red vectors, labeled \(k_1, k_2, k_3,\) and \(k_4\), represent the slopes used in the method. Vector \(k_1\) starts at \((t_0, y_0)\). Vectors \(k_2\) and \(k_3\) are evaluated at the midpoint \(t_0 + h/2\). Vector \(k_4\) is evaluated at the end of the interval \(t_0 + h\). A final point is labeled \((t_1, y_1)\) near the end of the interval on the blue curve.
PAGE 3

advantages: stability

\[ y' = -10y \]

A coordinate graph with blue axes. A solid black curve decays exponentially towards the x-axis. A dashed red line represents a linear approximation that overshoots the curve. Several red dots are plotted, some far above and one below the x-axis, illustrating how the solution can 'blow up' or become unstable if the step size h is too large.
Figure: A coordinate graph with blue axes. A solid black curve decays exponentially towards the x-axis. A dashed red line represents a linear approximation that overshoots the curve. Several red dots are plotted, some far above and one below the x-axis, illustrating how the solution can 'blow up' or become unstable if the step size h is too large.

could blow up if \( h \) is too big

w/ RK4 that is less likely to happen even w/ big \( h \)

errors:

  • Euler has global error \( \sim h \) (on the order of)

    (decrease error by factor of 10 \( \rightarrow \) 10 times as many steps)

  • Imp. Euler has global error \( \sim h^2 \)

    (doubling steps \( \rightarrow \) decrease error by factor of 4)

  • RK4 : \( \sim h^4 \)

    (double step count \( \rightarrow \) decrease error by factor of 16)

PAGE 4

example

\( y' = 1 - t + 4y \), \( y(0) = 1 \)

\( h = 0.1 \), estimate \( y(0.1) \)

Given:

  • \( t_0 = 0 \)
  • \( y_0 = 1 \)

\( t_1 = t_0 + h = 0.1 \) (target)

\( k_1 = f(t_0, y_0) = 1 - (0) + 4(1) = 5 \)

\( k_2 = f(t_0 + \frac{1}{2}h, y_0 + \frac{1}{2}k_1 h) \)
\( = 1 - (0 + 0.05) + 4(1 + \frac{1}{2} \cdot 5 \cdot 0.1) = 5.95 \)

\( k_3 = f(t_0 + \frac{1}{2}h, y_0 + \frac{1}{2}k_2 h) \)
\( = 1 - (0 + 0.05) + 4(1 + \frac{1}{2} \cdot 5.95 \cdot 0.1) = 6.14 \)

\( k_4 = f(t_0 + h, y_0 + k_3 h) \)
\( = 1 - (0 + 0.1) + 4(1 + 6.14 \cdot 0.1) = 7.356 \)

\[ y_1^* = y_0 + \frac{1}{6}(k_1 + 2k_2 + 2k_3 + k_4)h \]\[ = 1.60893 \]

PAGE 5

How good?

RK4 w/ \( h=0.1 \rightarrow 1.60893 \)

true value \( \rightarrow 1.60904 \)

error \( 1.085 \times 10^{-4} \)

RK4 w/ \( h=0.05 \rightarrow 1.609034 \) error \( 8 \times 10^{-6} \)

(decrease by factor of 14)

Euler w/ \( h=0.1 \rightarrow 1.5 \) (1 step) error \( 1 \times 10^{-1} \)

w/ \( h=0.01 \rightarrow 1.59529 \) (10 steps) error \( 1 \times 10^{-2} \)

w/ \( h=0.005 \rightarrow 1.60206 \)

Imp. Euler w/ \( h=0.1 \rightarrow 1.595 \)

(RK2) w/ \( h=0.01 \rightarrow 1.60886 \)

given \( h \), RK4 will always better (at least no worse) than Euler

beyond order 4, math gets messy

PAGE 6

Runge-Kutta-Fehlberg (RKF45)

The RKF45 method uses six stages to calculate both a 4th-order and a 5th-order approximation, allowing for adaptive step-size control.

\[ k_1 = f(t_n, y_n) \]\[ k_2 = f(t_n + \frac{1}{4}h, y_n + \frac{1}{4}hk_1) \]\[ k_3 = f(t_n + \frac{3}{8}h, y_n + \frac{3}{32}hk_1 + \frac{9}{32}hk_2) \]\[ k_4 = f(t_n + \frac{12}{13}h, y_n + \frac{1932}{2197}hk_1 - \frac{7200}{2197}hk_2 + \frac{7296}{2197}hk_3) \]\[ k_5 = f(t_n + h, y_n + \frac{439}{216}hk_1 - 8hk_2 + \frac{3680}{513}hk_3 - \frac{845}{4104}hk_4) \]\[ k_6 = f(t_n + \frac{1}{2}h, y_n - \frac{8}{27}hk_1 + 2hk_2 - \frac{3544}{2565}hk_3 + \frac{1859}{4104}hk_4 - \frac{11}{40}hk_5) \]

Final Estimates

The 4th-order estimate and the 5th-order estimate are calculated as follows:

\[ y_{n+1} = y_n + h \left( \frac{25}{216}k_1 + \frac{1408}{2565}k_3 + \frac{2197}{4104}k_4 - \frac{1}{5}k_5 \right) \]\[ \hat{y}_{n+1} = y_n + h \left( \frac{16}{135}k_1 + \frac{6656}{12825}k_3 + \frac{28561}{56430}k_4 - \frac{9}{50}k_5 + \frac{2}{55}k_6 \right) \]
PAGE 7

compare 4th-order to 5th-order

if \( |\text{difference}| \) is small \( \rightarrow h \) is ok, move on

if \( |\text{difference}| > \text{tolerance} \rightarrow h \) is too big, refine, repeat

ode45 in Matlab uses a different RK45 (Dormand-Prince)

  • \( \rightarrow \) change \( h \) dynamically and refine as need
    • straight portion: big \( h \) ok
    • curvy portion: small step size needed
PAGE 8

Adaptive Stepping in ode45: \( y' = 1 - t + 4y \)

A line graph titled 'Adaptive Stepping in ode45: y' = 1 - t + 4y'. The x-axis is labeled 'Time (t)' and ranges from 0 to 2. The y-axis is labeled 'Solution (y)' and ranges from 0 to 4000. The graph shows a curve starting at (0,0) and growing exponentially to approximately (2, 3500). A series of blue circular markers with red centers, labeled in the legend as 'Steps chosen by ode45', are plotted along the curve. The markers are very densely packed at the beginning and remain frequent throughout the steep ascent, illustrating the adaptive step-sizing of the numerical solver.
Figure: A line graph titled 'Adaptive Stepping in ode45: y' = 1 - t + 4y'. The x-axis is labeled 'Time (t)' and ranges from 0 to 2. The y-axis is labeled 'Solution (y)' and ranges from 0 to 4000. The graph shows a curve starting at (0,0) and growing exponentially to approximately (2, 3500). A series of blue circular markers with red centers, labeled in the legend as 'Steps chosen by ode45', are plotted along the curve. The markers are very densely packed at the beginning and remain frequent throughout the steep ascent, illustrating the adaptive step-sizing of the numerical solver.
Figure 1: Numerical solution and adaptive steps for the differential equation \( y' = 1 - t + 4y \).
PAGE 9

ode45 reacting to a 'Sharp Event'

A line graph titled 'ode45 reacting to a Sharp Event'. The vertical axis is labeled 'y' and ranges from -2 to 12 with increments of 2. The horizontal axis is labeled 'Time (t)' and ranges from 0 to 4 with increments of 0.5. The graph displays a blue line with red circular markers. The line is flat at y=0 from t=0 to approximately t=1.8. At t=1.8, the line rises sharply to a peak of approximately y=10.1 at t=2.1. After the peak, the line decreases in a smooth curve, reaching approximately y=0.5 at t=4. The red markers are widely spaced in the flat and slowly changing regions but become extremely dense during the sharp rise and peak, illustrating how the ode45 solver reduces its step size to maintain accuracy during rapid changes.
Figure: A line graph titled 'ode45 reacting to a Sharp Event'. The vertical axis is labeled 'y' and ranges from -2 to 12 with increments of 2. The horizontal axis is labeled 'Time (t)' and ranges from 0 to 4 with increments of 0.5. The graph displays a blue line with red circular markers. The line is flat at y=0 from t=0 to approximately t=1.8. At t=1.8, the line rises sharply to a peak of approximately y=10.1 at t=2.1. After the peak, the line decreases in a smooth curve, reaching approximately y=0.5 at t=4. The red markers are widely spaced in the flat and slowly changing regions but become extremely dense during the sharp rise and peak, illustrating how the ode45 solver reduces its step size to maintain accuracy during rapid changes.