Trapezoidal Rule
Contents
Trapezoidal Rule#
For the trapezoidal rule we approximate the integral of \(f(x)\) on the interval \([a-b]\) by constructing the trapezium below:
and calculating it’s area.
The area of the trapezium is given by:
In the case where \(f(a) < f(b)\), this area is given by:
In the case where \(f(a) > f(b)\), the area is give by:
which is the same as above, so in general we can approximate the integral as:
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).
To calculate this we use the sum:
where \(x_0 = a\) and \(x_n = b\). As we have specified that each of the \(n\) subintervals are of equal sizes, we have that:
we can therefore write the approximation as:
note how each \(f(x_i)\) in the sum above is repeated twice, except for \(f(x_0)\) and \(f(x_n)\), which only feature once each. We can now write the approximation as:
For a choice of \(n\) such that \(0 < \tfrac{b - a}{n} < 1\), the error for this method is \(O\left(\tfrac{1}{n}^2\right)\) [IntTrap1].
Composite Trapezoidal Rule with a Discrete Data Set#
Again, consider the data set \((x_i, y_i)\) for \(i = 0, \dots, n\), where
If we wanted to approximate the integral of this data set using the trapezoidal rule, we can apply this to each interval individually:
If the \(x_i\) values are evenly spaced, with \(x_i - x_{i-1} = \Delta x\) constant, then we can use the composite formula from the section above:
References#
- IntTrap1
James F. Epperson. An Introduction to Numerical Methods and Analysis. John Wiley & Sons, Inc., Hoboken, New Jersey, second edition edition, 2013.