Runge-Kutta Methods
This module illustrates Runge-Kutta methods for numerically solving
initial value problems for ordinary differential equations. A
numerical method for an ordinary differential equation (ODE) generates
an approximate solution step-by-step in discrete increments across the
interval of integration, in effect producing a discrete sample of
approximate values of the solution function. Given an ODE
y′ = f(t, y) and an
approximate solution value yk at
time tk, a Runge-Kutta method
approximates the solution
y(tk+1) at time
tk+1 = tk +
hk by
yk+1 = yk +
hkw, where w is a
weighted average value for the derivative y′
obtained by taking samples values
k1,…,kn
of the function f over the interval
[tk,
tk+1]. For example, the third-order
method included in this module takes three sample values
k1 = f(tk,
yk),
k2 = f(tk +
hk ⁄ 2, yk +
hk k1 ⁄ 2),
k3 = f(tk +
hk, yk +
hk(2 k2−
k1)),
and uses the weighted average
w = (k1 + 4k2 +
k3) ⁄ 6.
The user begins by selecting a differential equation and a specific
Runge-Kutta method from the menus provided. A solution value
y0 for the selected ODE at an initial time
t0 is marked in the left panel with a black dot. The
exact solution curve for the resulting initial value problem is drawn
in the left panel in black, and its derivative is shown in the right
panel. Starting from the initial value, the user advances the solution
through successive steps using the selected Runge-Kutta method. Each
step of the method is presented as a four-stage process. Each stage is
executed by clicking either Next or the currently highlighted
stage:
- Using the slider, the user can select any desired size
hk for the step from
tk to
tk+1, subject to minimum and
maximum allowed values. A red horizontal line in the left panel
indicates the length of the step that will be taken. Once the user has
set the slider for the desired step size, this choice takes effect by
clicking Choose Step Size or Next, which changes the
color of the line from red to black, indicating that the length of the
step is now fixed. The point at the end of the line, which will become
the next solution value, remains red, since its value is still to be
determined.
- The next stage is to estimate the average value of the derivative by
sampling the function f. The user clicks Sample
f to take each sample, with the number of samples
depending on the order of the method chosen. As each sample is taken,
its value is printed at the lower right and a dot of corresponding
color is drawn in the right panel. The dot indicates the value of t at
which the sample was taken and permits comparison of the sample value
with the derivative of the exact solution at that point. When all the
samples have been taken, the stage is completed by clicking Sample
Derivative or Next. The weighted average w is then printed
below the sample values and is also plotted in the right panel as a
horizontal line over the interval [tk,
tk+1]. The weighted average derivative
also determines the position of the next approximate solution point
yk+1, which accordingly changes from red to
black.
- The current step is concluded by clicking Take Step or
Next. The approximate and true solution values at the new point
are recorded in the table below, the exact solution to the ODE passing
through the new point is drawn in gray in the left panel, and its
derivative, also shown in gray, is added to the right panel.
- Preparation for another step is initiated by clicking Next Step
or Next, which displays the new step in red, ready for selecting
the new step size, with a default step size equal to the size of the
previous step, if possible.
Successive steps may be continued until the the interval has been
fully traversed. Note that the piecewise constant function plotted
on the right is the derivative of the piecewise linear approximation
to the solution function plotted on the left.
Reference: Michael T. Heath, Scientific Computing,
An Introductory Survey, 2nd edition, McGraw-Hill, New York,
2002. See Section 9.3.6, especially Example 9.12.
Developers: Evan VanderZee and Michael Heath