Numerical Integration Methods: Learn It 2

The Trapezoidal Rule

Sometimes rectangles aren’t the best shape for approximating the area under a curve. What if we used trapezoids instead? This often gives us better approximations, especially when the function has significant curvature.

Why do trapezoids work better? Rectangles create “steps” that miss curved portions of the function. Trapezoids follow the curve more closely by connecting function values with straight lines.

In Figure 2, the area beneath the curve is approximated by trapezoids rather than by rectangles.

This figure is a graph of a non-negative function in the first quadrant. The function increases and decreases. The quadrant is divided into a grid. Beginning on the x-axis at the point labeled a = x sub 0, there are trapezoids shaded whose heights are approximately the height of the curve. The x-axis is scaled by increments of a = x sub 0, x sub 1, x sub 2, x sub 3, and b = x sub 4.
Figure 2. Trapezoids may be used to approximate the area under a curve, hence approximating the definite integral.

How the Trapezoidal Rule Works

The trapezoidal rule approximates the area under a curve by dividing the region into trapezoids instead of rectangles. Each subinterval has equal width [latex]\Delta x[/latex], and the “height” of each trapezoid is [latex]\Delta x[/latex] (measured horizontally). The parallel bases have lengths [latex]f(x_i)[/latex] and [latex]f(x_{i+1})[/latex].

You’ll need the trapezoid area formula to calculate each piece:For a trapezoid with height [latex]h[/latex] and parallel bases of lengths [latex]b_1[/latex] and [latex]b_2[/latex], the area is [latex]\text{Area} = \frac{1}{2}h(b_1 + b_2)[/latex].

Let’s work through how we get the trapezoidal rule formula. Consider the first few trapezoids:

  • First trapezoid area: [latex]\frac{1}{2}\Delta x(f(x_0) + f(x_1))[/latex]
  • Second trapezoid area: [latex]\frac{1}{2}\Delta x(f(x_1) + f(x_2))[/latex]
  • Third trapezoid area: [latex]\frac{1}{2}\Delta x(f(x_2) + f(x_3))[/latex]
  • Fourth trapezoid area: [latex]\frac{1}{2}\Delta x(f(x_3) + f(x_4))[/latex]

When we add up all the trapezoid areas:

[latex]\int_a^b f(x),dx \approx \frac{1}{2}\Delta x(f(x_0) + f(x_1)) + \frac{1}{2}\Delta x(f(x_1) + f(x_2)) + \frac{1}{2}\Delta x(f(x_2) + f(x_3)) + \frac{1}{2}\Delta x(f(x_3) + f(x_4))[/latex]

Now here’s the key insight: factor out [latex]\frac{1}{2}\Delta x[/latex] and combine like terms:

[latex]\int_a^b f(x),dx \approx \frac{1}{2}\Delta x(f(x_0) + 2f(x_1) + 2f(x_2) + 2f(x_3) + f(x_4))[/latex]

Notice that the first and last function values appear once, while all the interior values are multiplied by 2. This pattern holds no matter how many subintervals you use!

This approach generalizes to give us the formal trapezoidal rule.

the trapezoidal rule

Assume that [latex]f\left(x\right)[/latex] is continuous over [latex]\left[a,b\right][/latex]. Let n be a positive integer and [latex]\Delta x=\frac{b-a}{n}[/latex]. Let [latex]\left[a,b\right][/latex] be divided into [latex]n[/latex] subintervals, each of length [latex]\Delta x[/latex], with endpoints at [latex]P=\left\{{x}_{0},{x}_{1},{x}_{2}\ldots ,{x}_{n}\right\}[/latex]. Set

[latex]{T}_{n}=\frac{1}{2}\Delta x\left(f\left({x}_{0}\right)+2f\left({x}_{1}\right)+2f\left({x}_{2}\right)+\cdots +2f\left({x}_{n - 1}\right)+f\left({x}_{n}\right)\right)[/latex].

Then, [latex]\underset{n\to \text{+}\infty }{\text{lim}}{T}_{n}={\displaystyle\int }_{a}^{b}f\left(x\right)dx[/latex].

Before we move forward, let’s unpack some important patterns you should notice about how the trapezoidal rule works.

The trapezoidal rule is actually an average: the trapezoidal rule [latex]T_n[/latex] is exactly the average of the left-hand and right-hand Riemann sums! Mathematically, this means:

[latex]T_n = \frac{1}{2}(L_n + R_n)[/latex]

where [latex]L_n = \sum_{i=1}^n f(x_{i-1})\Delta x[/latex] and [latex]R_n = \sum_{i=1}^n f(x_i)\Delta x[/latex]

This makes sense when you think about it—each trapezoid connects the left endpoint height to the right endpoint height with a straight line.

The shape of your function determines whether you’ll get an overestimate or underestimate:

  • Trapezoidal rule behavior:
    • Concave up functions: The rule systematically overestimates the integral (trapezoids sit above the curve)
    • Concave down functions: The rule systematically underestimates the integral (trapezoids sit below the curve)
  • Midpoint rule behavior: The midpoint rule is often more balanced. It tends to partially overestimate and partially underestimate over the same intervals, so these errors somewhat cancel each other out.
This figure has two graphs, both of the same non-negative function in the first quadrant. The function increases and decreases. The quadrant is divided into a grid. The first graph, beginning on the x-axis at the point labeled a = x sub 0, there are trapezoids shaded whose heights are approximately the height of the curve. The x-axis is scaled by increments of a = x sub 0, xsub1, x sub 2, x sub 3, and b = x sub 4. The second graph has on the x-axis at the point labeled a = x sub 0. There are rectangles shaded whose heights are approximately the height of the curve. The x-axis is scaled by increments of m sub 1, x sub 1, m sub 2, x sub 2, m sub 3, x sub 3, m sub 4 and b = x sub 4.
Figure 3. The trapezoidal rule tends to be less accurate than the midpoint rule.
In general, you can expect the midpoint rule to be more accurate than the trapezoidal rule for most functions. The midpoint rule’s error-canceling behavior gives it an edge!

Use the trapezoidal rule to estimate [latex]{\displaystyle\int }_{0}^{1}{x}^{2}dx[/latex] using four subintervals.

Watch the following video to see the worked solution to the example above.

For closed captioning, open the video on its original page by clicking the Youtube logo in the lower right-hand corner of the video display. In YouTube, the video will begin at the same starting point as this clip, but will continue playing until the very end.

You can view the transcript for this segmented clip of “3.6.1” here (opens in new window).