Integration — Special Cases 10

Numerical Integration
Trapezoid Rule, Simpson’s Rule & Error Bounds

Some integrals have no closed-form antiderivative. Others have one that is impractical to find. Numerical methods replace the exact antiderivative with a systematic approximation, and give you a guaranteed bound on how far off that approximation can be.

2Core Methods
8Worked Examples
2Error Formulas
10Quiz Questions
Share this page

§ 01When Exact Integration Fails

Not every integrand has a nice antiderivative. Functions like e−x², sin(x2), and √(1 + cos² x) cannot be expressed in terms of elementary functions, yet their definite integrals have perfectly well-defined numerical values. Numerical integration methods compute those values to any desired precision without ever finding an antiderivative.

Even when an exact antiderivative exists, numerical methods are often used in engineering and science because the integrand is given as a table of measured values rather than a formula. In those cases, no symbolic method applies at all.

Both methods on this page share the same setup: divide the interval [a, b] into n equal subintervals of width h = (b−a)/n, label the endpoints x0 = a, x1, x2, …, xn = b, and evaluate f at each node.

Common Setup for Both Methods
h = (b − a)/n     xi = a + ih     i = 0, 1, 2, …, n

n must be even for Simpson's Rule. It can be any positive integer for the Trapezoid Rule.

Relationship to Riemann Sums Riemann sums use rectangles. Numerical integration methods use better geometric shapes — trapezoids and parabolic arcs — to approximate the same area with far fewer subintervals. The Trapezoid Rule is exact for linear functions; Simpson's Rule is exact for polynomials of degree ≤ 3.

§ 02The Trapezoid Rule — Derivation and Formula

On each subinterval [xi−1, xi], replace the curve with the straight line connecting (xi−1, f(xi−1)) to (xi, f(xi)). The area under that line segment is the area of a trapezoid:

Area of One Trapezoid
Ai = (h/2)[f(xi−1) + f(xi)]

Summing all n trapezoids, the endpoint values f(x0) and f(xn) appear once each; every interior value f(xi) appears in two adjacent trapezoids and therefore carries coefficient 2.

Trapezoid Rule — Tn
Tn = (h/2)[ f(x0) + 2f(x1) + 2f(x2) + … + 2f(xn−1) + f(xn) ]
Coefficient pattern: 1, 2, 2, …, 2, 1  —  multiply by h/2

A compact shorthand: Tn = (h/2)[f(x0) + f(xn)] + h∑i=1n−1 f(xi). In plain English: half the step-size times (endpoints once, interior points twice).

Example 1 — Trapezoid Rule with n = 4

Example 01Approximate ∫13 (1/x) dx using T4
Setup
a=1, b=3, n=4  →  h = (3−1)/4 = 0.5x0=1,  x1=1.5,  x2=2,  x3=2.5,  x4=3
Values table
ixif(xi) = 1/xiCoefficientContribution
01.0001.000011.0000
11.5000.666721.3333
22.0000.500021.0000
32.5000.400020.8000
43.0000.333310.3333
Sum4.4667
Apply formula
T4 = (0.5/2) × 4.4667 = 0.25 × 4.4667
Result
T4 ≈ 1.1167     (exact: ln 3 ≈ 1.0986)

Example 2 — Trapezoid Rule with n = 6 on a Tabulated Function

Example 02Use T6 to estimate ∫03 f(x) dx given the table of values
Given data
x00.51.01.52.02.53.0
f(x)1.01.82.32.11.61.20.9
h = 0.5,  n = 6
Weighted sum
1(1.0) + 2(1.8) + 2(2.3) + 2(2.1) + 2(1.6) + 2(1.2) + 1(0.9)= 1.0 + 3.6 + 4.6 + 4.2 + 3.2 + 2.4 + 0.9 = 19.9
Result
T6 = (0.5/2) × 19.9 = 0.25 × 19.9 ≈ 4.975

§ 03Simpson’s Rule — Derivation and Formula

The Trapezoid Rule fits straight lines between nodes. Simpson's Rule does better: it fits a quadratic (parabolic arc) through each pair of consecutive subintervals. Since a parabola matches the curve at three points instead of two, the approximation is significantly more accurate for the same n.

On the subinterval [x0, x2], the unique parabola through (x0, f0), (x1, f1), (x2, f2) integrates to give area (h/3)[f0 + 4f1 + f2]. Applying this to every consecutive pair of subintervals and summing:

Simpson's Rule — Sn  (n must be even)
Sn = (h/3)[ f(x0) + 4f(x1) + 2f(x2) + 4f(x3) + 2f(x4) + … + 4f(xn−1) + f(xn) ]
Coefficient pattern: 1, 4, 2, 4, 2, …, 4, 2, 4, 1  —  multiply by h/3

The 1-4-2-4-2-…-4-1 pattern is the signature of Simpson's Rule. Interior odd-indexed points always carry coefficient 4; interior even-indexed points always carry coefficient 2; the two endpoints carry coefficient 1.

Simpson's Rule Requires Even n Each parabolic arc spans two subintervals. If n is odd, the intervals cannot be paired completely and the formula breaks down. Always choose an even value of n when applying Simpson's Rule — n = 4, 6, 8, … are all valid.

Example 3 — Simpson's Rule with n = 4

Example 03Approximate ∫13 (1/x) dx using S4
Setup
Same nodes as Example 1: h=0.5, x0=1, x1=1.5, x2=2, x3=2.5, x4=3
Values table
ixif(xi)Coeff (1,4,2,4,1)Contribution
01.0001.000011.0000
11.5000.666742.6667
22.0000.500021.0000
32.5000.400041.6000
43.0000.333310.3333
Sum6.6000
Apply formula
S4 = (0.5/3) × 6.6000 = (1/6) × 6.6000
Result
S4 ≈ 1.1000     (exact: ln 3 ≈ 1.0986  —  error < 0.002)

Example 4 — Simpson's Rule with n = 6

Example 04Approximate ∫03 e−x² dx using S6
Setup
h = (3−0)/6 = 0.5     xi = 0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0

This integrand has no elementary antiderivative: numerical integration is the only practical approach.

Values table
ixif(xi) = e−xi²CoeffContribution
00.01.00000011.000000
10.50.77880143.115203
21.00.36787920.735759
31.50.10539940.421598
42.00.01831620.036631
52.50.00193040.007722
63.00.00012310.000123
Sum5.317036
Apply formula
S6 = (0.5/3) × 5.317036 ≈ 0.8862
Result
03 e−x² dx ≈ 0.8862     (true value ≈ 0.8862 — excellent accuracy)
♦ ♦ ♦

§ 04Error Bounds — Guaranteed Accuracy

Numerical methods give approximations, but mathematics also provides hard upper bounds on how wrong those approximations can be. The error bounds below guarantee that the true error cannot exceed the stated value: regardless of the specific function values.

Trapezoid Rule Error Bound — |ET|
|ET| ≤ M2(b−a)3 / (12n2)

where M2 = max|f′′(x)| on [a, b]. The error shrinks as 1/n², doubling n quarters the error.

Simpson’s Rule Error Bound — |ES|
|ES| ≤ M4(b−a)5 / (180n4)

where M4 = max|f(4)(x)| on [a, b]. The error shrinks as 1/n4, doubling n reduces error by a factor of 16. This is why Simpson's Rule is dramatically more efficient than the Trapezoid Rule for smooth functions.

Interpreting the Error Bounds Both bounds give a worst-case guarantee. The actual error is usually much smaller. Also note: if f′′ = 0 on [a,b] (f is linear), the Trapezoid Rule is exact with zero error. If f(4) = 0 on [a,b] (f is a cubic polynomial), Simpson's Rule is exact. This explains why the error bounds involve the second and fourth derivatives respectively.

Example 5 — Trapezoid Error Bound

Example 05Find n so that Tn approximates ∫13 (1/x) dx with error < 0.001
Find M2
f(x) = 1/x  →  f′(x) = −1/x2  →  f′′(x) = 2/x3

On [1, 3], f′′ is decreasing, so max is at x = 1: M2 = 2/13 = 2.

Set up inequality
|ET| ≤ 2 × (3−1)3 / (12n2) = 2 × 8 / (12n2) = 16/(12n2) = 4/(3n2)Require: 4/(3n2) < 0.001  →  n2 > 4/(0.003) ≈ 1333  →  n > 36.5
Result
Use n ≥ 37 (or round up to n = 40 for a round number). T37 guarantees error < 0.001.

Example 6 — Simpson's Error Bound

Example 06Find n so that Sn approximates ∫01 ex dx with error < 0.00001
Find M4
f(x) = ex  →  f(4)(x) = ex

On [0,1], max|f(4)| = e1 = e ≈ 2.718. So M4 = e.

Set up inequality
|ES| ≤ e(1−0)5 / (180n4) = e/(180n4)Require: e/(180n4) < 0.00001  →  n4 > e/0.0018 ≈ 1510  →  n > 6.23
Result
Use n = 8 (next even integer ≥ 7). S8 guarantees error < 0.00001.

§ 05Comparison, Accuracy and When to Use Each Method

PropertyTrapezoid RuleSimpson's Rule
Geometric shape usedStraight lines (trapezoids)Parabolic arcs
Coefficient pattern1, 2, 2, …, 2, 11, 4, 2, 4, …, 4, 1
Multiplierh/2h/3
n restrictionAny positive integerMust be even
Exact forLinear functions (degree ≤ 1)Polynomials of degree ≤ 3
Error orderO(h²) — error ∝ 1/n²O(h4) — error ∝ 1/n4
Derivative needed for error boundf′′ (second derivative)f(4) (fourth derivative)
Best suited forTabulated data with any spacing; quick estimates; linear-ish integrandsSmooth functions; when high accuracy is needed with fewer intervals

For a smooth function, Simpson's Rule with n = 8 will typically outperform the Trapezoid Rule with n = 100. When the integrand is given only as a table of values with no formula, both rules apply, but the Trapezoid Rule is simpler and has no parity requirement on n.

Example 7 — Comparing Both Methods on the Same Integral

Example 07Approximate ∫0π/2 cos x dx using T4 and S4; compare with exact value
Setup
h = (π/2)/4 = π/8 ≈ 0.3927     Exact value: [sin x]0π/2 = 1
Node values
ixicos(xi)
001.000000
1π/8 ≈ 0.39270.923880
2π/4 ≈ 0.78540.707107
33π/8 ≈ 1.17810.382683
4π/2 ≈ 1.57080.000000
T4
= (π/8)/2 × [1(1) + 2(0.9239) + 2(0.7071) + 2(0.3827) + 1(0)] = (π/16) × 5.0274 ≈ 0.9871
S4
= (π/8)/3 × [1(1) + 4(0.9239) + 2(0.7071) + 4(0.3827) + 1(0)] = (π/24) × 7.6284 ≈ 0.9998
Comparison
T4 ≈ 0.9871  (error 0.0129)     S4 ≈ 0.9998  (error 0.0002)     Exact: 1

Example 8 — Finding the Minimum n for a Given Accuracy

Example 08How many intervals does Simpson's Rule need to approximate ∫02 x4 dx to within 0.0001?
Find M4
f(x) = x4  →  f(4)(x) = 24  →  M4 = 24 (constant)
Error bound
|ES| ≤ 24 × (2−0)5 / (180n4) = 24 × 32 / (180n4) = 768/(180n4) = 4.267/n4Require 4.267/n4 < 0.0001  →  n4 > 42667  →  n > 14.4
Note

Since f(4)(x) = 24 (a polynomial of degree exactly 4), and the Simpson error bound involves f(4), you might expect exact results for lower degree polynomials. Indeed, for f = x3, f(4) = 0 and Simpson's Rule is exact with any even n.

Result
Use n = 16 (next even integer ≥ 15). S16 guarantees error < 0.0001.

§ 0610-Question Quiz

Test your understanding of both numerical methods, coefficient patterns, and error bounds.

§ 07Continue the Integration Series

Cookie Settings