Trapezoidal Rule#
For the trapezoidal rule we approximate the integral of \(f(x)\) on the interval \([a-b]\) by constructing the trapezium below:
![../../../_images/a39f96798400bdb07273ae3d36f2cbd0afc9170dd83c681d08db96fec1a59526.png](../../../_images/a39f96798400bdb07273ae3d36f2cbd0afc9170dd83c681d08db96fec1a59526.png)
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).
![../../../_images/8e8c959b422c651c87c3a5ab7d8c0f6b9f917dccb1608294799e6b52e34515d1.png](../../../_images/8e8c959b422c651c87c3a5ab7d8c0f6b9f917dccb1608294799e6b52e34515d1.png)
![../../../_images/80d0d2258e2e2c1886110609d9d41f2d74686a1b62b7c1e2ed01187ca4ae67b3.png](../../../_images/80d0d2258e2e2c1886110609d9d41f2d74686a1b62b7c1e2ed01187ca4ae67b3.png)
![../../../_images/e55392412bf4404dc59219046f58a140bd3a40123e1a7641f2439f83ed5973ac.png](../../../_images/e55392412bf4404dc59219046f58a140bd3a40123e1a7641f2439f83ed5973ac.png)
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.