Scientific Computing

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*)*y*_{k}*t*_{k}*y*(*t*_{k+1})*t*_{k+1} = *t*_{k} +
*h*_{k}*y*_{k+1} = *y*_{k} +
*h*_{k}*w**w* is a
weighted average value for the derivative *y*′*k*_{1},…,*k*_{n}*f* over the interval
*t*_{k},
*t*_{k+1}]

*k*_{1} = *f*(*t*_{k},
*y*_{k}),

*k*_{2} = *f*(*t*_{k} +
*h*_{k} ⁄ 2, *y*_{k} +
*h*_{k} *k*_{1} ⁄ 2),

*k*_{3} = *f*(*t*_{k} +
*h*_{k}, *y*_{k} +
*h*_{k}(2 *k*_{2}−
*k*_{1})),

and uses the weighted average
*w* = (*k*_{1} + 4*k*_{2} +
*k*_{3}) ⁄ 6.

The user begins by selecting a differential equation and a specific
Runge-Kutta method from the menus provided. A solution value
*y*_{0} for the selected ODE at an initial time
*t*_{0} 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
*h*_{k}for the step from*t*_{k}to , 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*t*_{k+1}*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*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*f**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[ . The weighted average derivative also determines the position of the next approximate solution point*t*_{k},*t*_{k+1}]*y*_{k+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