Interactive Educational Modules in
Scientific Computing

Trapezoid Method

This module illustrates the implicit trapezoid method 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. The trapezoid method averages the Euler and backward Euler methods, advancing the approximate solution at each step along a line whose slope is the arithmetic mean of the derivatives at its endpoints. Specifically, from an approximate solution value yk at time tk for an ODE y′ = f(t, y), the trapezoid method approximates the solution y(tk+1) at time tk+1 = tk + hk by solving the implicit equation yk+1 = yk + hk [f(tk, yk) + f(tk+1, yk+1)] ⁄ 2 for yk+1. Since this equation may be nonlinear, solving it generally requires an iterative solution method. Both functional iteration and Newton's method are provided as options for solving the implicit equation, with a starting guess provided by the explicit Euler's method.

The user begins by selecting a differential equation from the menu provided. A solution value y0 for the selected ODE at an initial time t0 is marked with a black dot, and the exact solution curve for the resulting initial value problem is drawn in black. Starting from this initial value, the user advances the solution through successive steps using the trapezoid method. The graphical display has two modes, a basic display for showing the overall progress of the numerical solution of the ODE, and an alternate display for showing the solution of the implicit equation at each step:

  • In the basic display, seen initially, the exact solution to the initial value problem and the portion of the approximate numerical solution already computed are drawn in black. For each point of the approximate numerical solution except the initial value, the exact solution to the ODE that passes through that point is drawn in gray.
  • In the alternate display, the black point is the previous approximate solution value and the red point is the next approximate solution value, currently being determined. The exact solution to the ODE passing through the known solution point is drawn in light blue, and the tangent line at that point is shown in dark blue. The exact solution to the ODE passing through the new solution point is drawn in pink, and its tangent line is shown in red. A green line with slope equal to the average of the endpoint derivatives is drawn through the intersection of the tangent lines.

To perform a step of the trapezoid method, the user executes each of four stages by clicking either Next or the currently highlighted stage:

  1. 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. The starting guess given by Euler's method using the currently selected step size is shown in red, and it varies as the step size varies. Once the user has set the slider for the desired step size, this choice takes effect by clicking Choose Step Size or Next, which causes the graph to change from the basic to the alternate display in preparation for the next stage.
  2. The next stage is to solve the implicit equation. The user chooses either functional iteration or Newton's method and then performs one or more iterations of the selected nonlinear equation solver by clicking Iterate as many times as desired. Progress towards convergence can be observed graphically, since at a solution to the implicit equation, the black line segment connecting the approximate solution points will be parallel to the green line. The residual (i.e., the difference between the right and left sides of the implicit equation) is printed below as another measure of convergence. Note that the nonlinear equation methods may not always converge, especially if the step size is too large. When the user is satisfied with the convergence of the iterative solver, this stage is terminated by clicking Solve Implicit Equation or Next, which returns the graph to the basic display, preserving the new solution point (changing it from red to black) and the exact solution passing through it.
  3. The current step is concluded by clicking Take Step or Next, which prints in the table below the approximate and true solution values at the new point and changes the color of the exact solution to the ODE passing through the new solution point from pink to gray.
  4. 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.

Reference: Michael T. Heath, Scientific Computing, An Introductory Survey, 2nd edition, McGraw-Hill, New York, 2002. See Section 9.3.3.

Developers: Evan VanderZee and Michael Heath