18.2 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:
This can be shown [IntTrap1] to have an error of:
for some \(\xi \in [a, b]\). Note that this is double the error of the midpoint rule. As before, a large interval will have a large error, to reduce this we can sub-divide the interval.
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\) sub-intervals are of equal sizes, we have that:
we can therefore write \(T_n(f)\) 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 \(T_n(f)\) as:
This can be shown [IntTrap1] to have a (global) error of:
for some different \(\xi \in [a, b]\). Again, this is double the error of the composite midpoint rule.
Composite Trapezoidal Rule with a Discrete Data Set#
The composite trapezoidal rule can be used to integrate a discrete set of data. Consider a discrete set of data points \((x_i, y_i)\) for \(i = 0, \dots, n\), where:
We want to approximate the integral of \(f(x)\) on the interval \([x_0, x_n]\) using this data.
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: