Mathematics Source Library
C & ASM

 Home Differential Equations Home Euler's Method Trapezoidal Method Midpoint Method Modified Midpoint (Gragg's) Method Runge-Kutta Methods Adams-Bashforth Adams-Moulton Methods Embedded Runge-Kutta Methods Gragg - Bulirsch-Stoer Method Second Order Diff Eq Methods

## Trapezoidal Method

The trapeziodal method is an implicit method for approximating the solution of the initial value problem y' = f(x,y);  y(x0) = y0 at x for a given step size h. The trapezoidal method can be derived by expanding y(x) in a Taylor series

y(x+h) = y(x) + h y'(x) + (h2/2) y''(x) + O(h3)

and then subsituting (y'(x+h) - y(x))/h for y''(x) followed by substituting f(x,y) for y'(x). The approximation for y(x+h) is then given implicitly by

y(x+h) = y(x) + (h / 2) (f(x,y(x)) + f(x+h,y(x+h))).
or
y(x+h) - (h / 2) f(x+h,y(x+h)) = y(x) + (h / 2) f(x,y(x)).

In order to use the trapezoidal method, the user must program a function g whose value is that value of y such that

y(x+h) - h' f(x+h,y(x+h)) = u,

where h'=h / 2 and u = y(x) + h' f(x,y(x)), i.e.

g(x+h,h',u) - h' f(x+h,g(x+h,h',u)) = u.

Locally the trapezoidal method is a third order method and therefore globally a second order method.

The trapezoidal method is a stable and convergent method with region of absolute stability

| (2 + µh) / (2 - µh) | < 1

in the complex µh plane.

As a rule, the trapezoidal method is convenient if the function g(x,h,u) is simple.

### Function List

• double Trapezoidal_Method( double (*f)(double, double), double (*g)(double,double,double), double y0, double x0, double h, int number_of_steps )

This function uses the trapezoidal method to return the estimate of the solution of the initial value problem, y' = f(x,y);  y = y0 when x = x0, at x0 + nh where n is the number_of_steps and h is the step size. The user supplied function g(x,h,u) returns the value of y such that y - h * f(x,y) = u (here h is the step size / 2).

• void Trapezoidal_Integral_Curve( double (*f)(double, double), double (*g)(double,double,double), double y[ ], double x0, double h, int number_of_steps_per_interval, int number_of_intervals )

This function uses the trapezoidal method to estimate the solution, y[n], of the initial value problem, y' = f(x,y);  y = y when x = x0, at x0+nmh where n is the interval number n = 1, ..., number_of_intervals, m is the number_of_steps_per_interval and h is the step size. Note that on input y is the user-specified initial value at x = x0. The user supplied function g(x,h,u) returns the value of y such that y - h * f(x,y) = u (here h is step size / 2).

#### C Source Code

• The file, trapezoidal_method.c, contains versions of Trapezoidal_Method( ) and Trapezoidal_Integral_Curve( ) written in C.