Subject : The following demonstrates the Trapezoidal method of estimating integrals of continuous functions.
Authors : Nathan Collier, Autar Kaw, Loubna Guennoun
Date : 25 October 2005

Introduction

Trapezoidal rule is based on the Newton-Cotes formula that if one approximates the integrand of the integral by an nth order polynomial, then the integral of the function is approximated by the integral of that nth order polynomial. Integration of polynomials is simple and is based on the calculus.  Trapezoidal rule is the area under the curve for a first order polynomial (straight line) that approximates the integrand.  [click here for textbook notes] [click here for power point presentation].

Inputs

The following simulation illustrates the Trapezoidal rule of integration. This section is the only section where the user interacts with the program. The user enters any function f(x), the lower and upper limits of the integration, a and b respectively. By entering this data, the program will calculate  the results using Trapezoidal rule for n = 1, 2, 3, and 4 segments.

Integrand f[x] = 0

f[x_] := 300.0*x/(1.0 + Exp[x]);

Lower and upper limit of the integral, a and b respectively.

a = 0.0;
b = 10.0;

curve = 
        Plot[f[x], {x, a, b}, 
          PlotLabel -> "Entered function on given interval", 
          TextStyle -> {FontSize -> 
                11}];
General::spelll  Off

1 Segment Trapezoidal Rule

n = 1;
h1 = (b - a)/n

The integral of the function f(x) from a to b using the trapezoidal rule with one segment will be equal to:

s1 = h1*(f[a] + f[b])/2

The approximate error and absolute relative approximate error for the first iteration are undefined.

2 Segment Trapezoidal Rule

n = 2;
h2 = (b - a)/n

The integral of the function f(x) from a to b using the trapezoidal rule with two segments will be equal to:

s2 = h2*(f[a] + 2*f[a + h2] + f[b])/2

The approximate error is:

Ea2 = s2 - s1

The absolute relative approximate error is

ea2 = Abs[Ea2/s2]*100

3 Segment Trapezoidal Rule

n = 3;
h3 = (b - a)/n

The integral of the function f(x) from a to b using the trapezoidal rule with three segments will be equal to:

summ = f[a + h3] + f[a + 2*h3];
s3 = h3*(f[a] + 2*summ + f[b])/2

The approximate error is:

Ea3 = s3 - s2

The absolute relative approximate error is

ea3 = Abs[Ea3/s3]*100

4 Segment Trapezoidal Rule

n = 4;
h4 = (b - a)/n

The integral of the function f(x) from a to b using the trapezoidal rule with four segments will be equal to:

summ = 
        f[a + h4] + f[a + 2*h4] + f[a + 3*h4];
s4 = h4*(f[a] + 2*summ + f[b])/2

The approximate error is:

Ea4 = s4 - s3

The absolute relative approximate error is

ea4 = Abs[Ea4/s4]*100