Math glossary

Trapezoidal Rule: Formula, Error Bound, and Examples

Estimate integrals with equal or unequal trapezoids. Compare the result with the exact value and check the error bound with six examples.

TL;DR

The trapezoidal rule estimates a definite integral by joining neighbouring sample points with straight lines. Multiply each interval width by the average of its endpoint heights. Add those signed contributions over the full interval.

Key Points

  • A single trapezoid uses two endpoint values.
  • In an equally spaced composite rule, interior values count twice in the usual formula.
  • For unequally spaced points, calculate each interval using its own width.
  • The rule is exact for linear functions because the chords follow the graph.
  • Curvature determines the error, and a second-derivative bound can guide the number of intervals.

What is the trapezoidal rule?

For a function ff on [a,b][a,b], approximate the curve by the segment connecting (a,f(a))(a,f(a)) and (b,f(b))(b,f(b)). The signed integral of that segment is its width times its average height:

T1=b−a2(f(a)+f(b)).T_1=\frac{b-a}{2}\bigl(f(a)+f(b)\bigr).

When both heights are positive, this is the familiar trapezoid area. A graph below the horizontal axis contributes a negative value to the definite integral. The formula automatically keeps that sign. For background on the geometric area, see the trapezoid area guide. OpenStax, Numerical Integration

Three straight segments above a convex curve form trapezoids over adjacent intervals
For this convex curve, each chord lies above its interval. The sum of the trapezoids overestimates the integral.

How do you use the composite trapezoidal rule?

Divide [a,b][a,b] into nn equal subintervals. Write h=(b−a)/nh=(b-a)/n and xi=a+ihx_i=a+ih for i=0,…,ni=0,\ldots,n. The usual form is

Tn=h2[f(x0)+2∑i=1n−1f(xi)+f(xn)].T_n=\frac h2\left[f(x_0)+2\sum_{i=1}^{n-1}f(x_i)+f(x_n)\right].

The two outer endpoints appear once. Each interior value is the right endpoint of one trapezoid and the left endpoint of the next, so it appears twice. This is also the average of the left and right endpoint sums for the same equal-width partition. University of Nebraska–Lincoln, Numerical Integration

For unequal spacings, use half the sum of each pair of heights multiplied by its own width. Add those local values. Using one common width for irregular time readings or uneven measurement locations would pair values with the wrong intervals. University of California, Berkeley, Numerical Integration

When does the rule overestimate or underestimate?

If the graph is convex on the interval, each chord lies above it, so the estimate is at least as large as the actual integral. For a concave graph, the chords lie below it. A function can change curvature, in which case different local errors can offset each other.

If f″f'' is continuous on [a,b][a,b] and |f″(x)|≤M\lvert f''(x)\rvert\le M, the equal-width composite error satisfies

|Tn−∫abf(x)dx|≤M(b−a)312n2.\left|T_n-\int_a^b f(x)\,dx\right| \le\frac{M(b-a)^3}{12n^2}.

This is an upper bound for the magnitude of error, rather than the error itself. Doubling nn divides the bound by four. The function extrema guide can help find a maximum of |f″|\lvert f''\rvert on a closed interval. University of Waterloo, Composite Trapezoidal Rule

How does trapezoidal integration compare with other rules?

The left and right endpoint rules use one height per subinterval and form rectangles. The midpoint rule uses the centre height. The trapezoidal rule uses both endpoints and forms a straight-line cap. Simpson’s rule fits quadratic pieces to sampled points and, in its standard composite form, uses an even number of equal subintervals. Choose according to the available sample positions and smoothness of the function. CLP Integral Calculus, Numerical Integration

Worked Trapezoidal Rule Examples

Example 1

Use a single trapezoid for f(x)=x+1f(x)=x+1 from 0 to 4.

  1. The width is 4 and the endpoint heights are 1 and 5.
  2. Their average is 3, so the estimate is 4(3)=124(3)=12.
  3. The function is linear, so this equals the exact integral.

Example 2

Use four equal trapezoids for f(x)=x2f(x)=x^2 from 0 to 2.

  1. The width is 1/21/2. The values at the five endpoints are 0,1/4,1,9/4,40,1/4,1,9/4,4.
  2. Double the three interior values and add the outer ones. The weighted sum is 11.
  3. Multiply by h/2=1/4h/2=1/4. The result is 11/4=2.7511/4=2.75. The exact value is 8/38/3, so the overestimate is 1/121/12.

Example 3

Approximate the integral from table points (0,2)(0,2), (1,4)(1,4), and (3,5)(3,5).

  1. The first interval has width 1 and average height 3, giving 3.
  2. The second interval has width 2 and average height 4.5, giving 9.
  3. The sum is 12. Each interval used its own width.

Example 4

Apply two trapezoids to f(x)=4−x2f(x)=4-x^2 on [0,2][0,2].

  1. Use width 1 and heights 4, 3, and 0.
  2. The composite estimate is (4+2(3)+0)/2=5(4+2(3)+0)/2=5.
  3. The exact integral is 16/316/3. The approximation is smaller, matching the expected sign for a concave function.

Example 5

Choose enough equal trapezoids to guarantee an error at most 0.001 for f(x)=exf(x)=e^x on [0,1][0,1].

  1. The second derivative is exe^x, whose maximum on this interval is ee.
  2. Require e/(12n2)≤0.001e/(12n^2)\le0.001. This gives n≥e/0.012n\ge\sqrt{e/0.012}, slightly above 15.
  3. Choose 16 equal intervals. The bound is then below 0.001.

Example 6

Speed readings at 0, 2, and 4 seconds are 0, 2, and 5 metres per second. Estimate the distance covered.

  1. The first interval contributes 2(0+2)/2=22(0+2)/2=2 metres.
  2. The second contributes 2(2+5)/2=72(2+5)/2=7 metres.
  3. The estimated distance is 9 metres. The units follow from multiplying speed by time.

Mistakes That Change a Trapezoidal Estimate

Mistake 1: Doubling the first and last values

Only interior values occur in two neighbouring trapezoids. Use the outer endpoints once.

Mistake 2: Using the full interval width in every trapezoid

For equally spaced points, each width is (b−a)/n(b-a)/n. For unequal spacing, subtract each neighbouring pair of inputs.

Mistake 3: Treating the error bound as the exact error

The bound is a guarantee under its assumptions. The actual error can be smaller and may be positive or negative.

Try It Yourself

  1. Use one trapezoid for f(x)=2xf(x)=2x on [0,3][0,3].
  2. Find the composite estimate for heights 1, 4, and 6 at inputs 0, 2, and 4.
  3. How does the error bound change if you triple the number of equal intervals?

Answers and Reasoning

  1. The width is 3 and the average height is 3. The estimate is 9 and is exact.
  2. Compute (2/2)(1+2(4)+6)=15(2/2)(1+2(4)+6)=15.
  3. It becomes one-ninth as large because the denominator contains n2n^2.

Frequently Asked Questions

What if the function crosses below zero?

The formula approximates signed integral. If total unsigned area is required, split at zeros and accumulate positive magnitudes.

Is the trapezoidal rule exact for a constant function?

Yes. A constant is linear with slope zero, so the approximating segments follow its graph exactly.

Do you need even numbers of subintervals?

No. Any positive whole number of intervals can be used. The even-subinterval requirement applies to the standard composite Simpson rule.

Conclusion

  • Average endpoint values within each interval and multiply by its width.
  • Use the composite weights only for equal spacing.
  • Check curvature or a second-derivative bound when accuracy matters.

Read More

Research Behind This Article

  1. OpenStax, Calculus Volume 2: Numerical Integration. OpenStax
  2. University of Nebraska–Lincoln, Active Calculus: Numerical Integration. UNL
  3. Per-Olof Persson, Numerical Differentiation and Integration. UC Berkeley
  4. Douglas W. Harder, Composite Trapezoidal Rule. University of Waterloo
  5. Joel Feldman, Andrew Rechnitzer and Elyse Yeager, CLP Integral Calculus: Numerical Integration. CLP Calculus