Trapezoidal Rule#

For the trapezoidal rule we approximate the integral of f(x) on the interval [ab] by constructing the trapezium below:

../../../_images/trapezoidal_4_0.png

and calculating it’s area.

The area of the trapezium is given by:

Atrapezoid=Arectangle+Atriangle

In the case where f(a)<f(b), this area is given by:

Atrapezoid=(ba)f(a)+12(ba)[f(b)f(a)]=12(ba)[f(a)+f(b)]

In the case where f(a)>f(b), the area is give by:

Atrapezoid=(ba)f(b)+12(ba)[f(a)f(b)]=12(ba)[f(a)+f(b)]

which is the same as above, so in general we can approximate the integral as:

abf(x) dx12(ba)[f(a)+f(b)]

Composite Trapezoid Rule#

Now, if we were to break up this interval into n equal sub-intervals, and approximate the integral on each of these, we arrive at the composite trapezoidal rule (illustrated in the diagrams that follow).

../../../_images/trapezoidal_8_0.png ../../../_images/trapezoidal_8_1.png ../../../_images/trapezoidal_8_2.png

To calculate this we use the sum:

abf(x) dxi=1n12(xixi1)[f(xi1)+f(xi)]

where x0=a and xn=b. As we have specified that each of the n subintervals are of equal sizes, we have that:

xixi1=ban

we can therefore write the approximation as:

abf(x) dxba2ni=1n[f(xi1)+f(xi)]

note how each f(xi) in the sum above is repeated twice, except for f(x0) and f(xn), which only feature once each. We can now write the approximation as:

abf(x) dxba2n[f(a)+2{i=1n1f(xi)}+f(b)]

For a choice of n such that 0<ban<1, the error for this method is O(1n2) [IntTrap1].

Composite Trapezoidal Rule with a Discrete Data Set#

Again, consider the data set (xi,yi) for i=0,,n, where

f(xi)=yi

If we wanted to approximate the integral of this data set using the trapezoidal rule, we can apply this to each interval individually:

x0xnf(x) dx12i=1n(xixi1)[yi1+yi]

If the xi values are evenly spaced, with xixi1=Δx constant, then we can use the composite formula from the section above:

x0xnf(x) dxΔx2[y0+2{i=1n1yi}+yn]

References#

IntTrap1

James F. Epperson. An Introduction to Numerical Methods and Analysis. John Wiley & Sons, Inc., Hoboken, New Jersey, second edition edition, 2013.