Calculus › Section I · Integration techniques and improper integrals › Topic I.6

Numerical integration: trapezoid and Simpson's rules

Most definite integrals have no antiderivative you can write down — e^(x²), sin(x²), eˣ/x all resist every technique in this chapter. But a definite integral is just a number, and numbers can be approximated: slice the region into simple shapes and add their areas. The trapezoid rule uses straight tops; Simpson's rule fits parabolas, and the accuracy jumps dramatically.

The trapezoid rule

Split \([a, b]\) into \(n\) equal subintervals of width \(h = \frac{b - a}{n}\), with sample points \(x_0 = a, x_1, \dots, x_n = b\). Each adjacent pair of samples forms a trapezoid: width \(h\), parallel sides \(f(x_i)\) and \(f(x_{i+1})\), area \(\frac{h}{2}(f(x_i) + f(x_{i+1}))\). Adding all \(n\) trapezoids, every interior sample is counted twice:

T_n = \frac{h}{2}\left[f(x_0) + 2f(x_1) + 2f(x_2) + \cdots + 2f(x_{n-1}) + f(x_n)\right]

The weight pattern is easy to remember: ends get 1, everything between gets 2. Straight tops systematically overestimate where the curve bends upward (the chord sits above the curve) and underestimate where it bends downward — the errors come from bending, not from the arithmetic.

Worked example: trapezoid on a known area

Approximate \(\int_0^1 \frac{dx}{1 + x^2}\), whose exact value is \(\arctan 1 = \frac{\pi}{4} \approx 0.7853982\) — so the error is measurable. With \(n = 4\), \(h = 0.25\):

f(0) = 1,\ f(0.25) = 0.9411765,\ f(0.5) = 0.8,\ f(0.75) = 0.64,\ f(1) = 0.5
T_4 = \frac{0.25}{2}\left[1 + 2(0.9411765) + 2(0.8) + 2(0.64) + 0.5\right] = 0.125 \times 6.2623529 = 0.7827941

The error is \(0.7827941 - 0.7853982 = -0.0026\): about a third of one percent, from four trapezoids.

Simpson's rule: parabolas instead

Straight tops are crude; Simpson's rule fits a parabola through each consecutive triple of points, which hugs the curve far better. The rule needs pairs of subintervals, so \(n\) must be even:

S_n = \frac{h}{3}\left[f(x_0) + 4f(x_1) + 2f(x_2) + 4f(x_3) + \cdots + 2f(x_{n-2}) + 4f(x_{n-1}) + f(x_n)\right]

The weights run \(1, 4, 2, 4, 2, \dots, 2, 4, 1\): ends get 1, odd-indexed points get 4, even-indexed interior points get 2. A quirk worth knowing: although Simpson's rule is built from parabolas, it integrates any cubic polynomial exactly — the cubics' extra freedom cancels out over each pair of intervals.

Worked example: Simpson on the same integral

Apply Simpson's rule with \(n = 4\) to the same \(\int_0^1 \frac{dx}{1+x^2}\), reusing the same five sample values:

S_4 = \frac{0.25}{3}\left[1 + 4(0.9411765) + 2(0.8) + 4(0.64) + 0.5\right]
= \frac{1}{12}\left[1 + 3.7647059 + 1.6 + 2.56 + 0.5\right] = \frac{9.4247059}{12} = 0.7853922

The error is now \(-0.0000060\) — roughly 430 times smaller than the trapezoid's, from the same five function values. That is the whole sales pitch for parabolas: no new data, vastly better fit, because smooth curves simply are closer to parabolas than to straight lines.

How the errors behave

The trapezoid rule's error shrinks like \(h^2\): halve the width and the error drops to about a quarter. Simpson's error shrinks like \(h^4\): halve the width and the error drops to about a sixteenth. This is why Simpson's rule is the practical default. Concavity also predicts the trapezoid's sign: on a concave-up stretch the chord lies above the curve, so the trapezoid rule overestimates; concave down, it underestimates. Simpson's rule has no such simple sign rule. And the error bound formulas make accuracy plannable:

|E_T| \le \frac{(b-a)^3}{12n^2}\max|f''|, \qquad |E_S| \le \frac{(b-a)^5}{180n^4}\max|f^{(4)}|

For example, with \(\max|f''| \le 2\) on \([0,1]\), the trapezoid rule guarantees \(0.001\) accuracy once \(\frac{1}{6n^2} \le 0.001\), that is \(n \ge 13\).

Worked example: an impossible antiderivative

\(\int_0^1 e^{x^2}\,dx\) has no elementary antiderivative — no combination of standard functions differentiates to \(e^{x^2}\) — yet the area itself is perfectly definite, and it matters in statistics and physics. With \(n = 4\), \(h = 0.25\):

f(0) = 1,\ f(0.25) = 1.0644945,\ f(0.5) = 1.2840254,\ f(0.75) = 1.7550546,\ f(1) = 2.7182818

Trapezoid: \(T_4 = 0.125 \times 11.9254312 = 1.4906789\). Simpson: \(S_4 = \frac{1}{12}(17.5645286) = 1.4637107\). The true value is \(1.4626517\): the trapezoid is \(+0.028\) high — expected, since \(e^{x^2}\) is concave up throughout — while Simpson is \(+0.0011\), twenty-six times closer, again from identical data.

When numerical rules are the only option

Real-world integrals are more often impossible than not: bell-curve tails \(\int e^{-x^2/2}\,dx\), diffraction patterns \(\int \sin(x^2)\,dx\), functions known only as measured data — a sensor reading every millisecond has no formula at all, just samples, and the trapezoid rule applies to it directly. Spreadsheets and every numerical computing package use exactly these rules (or refinements of them) — Simpson's rule, or its adaptive descendants, is what lies behind a calculator's ∫ button. The craft decisions are: which rule, how many subintervals, and how many digits to trust, all answered by the error formulas.

Common mistakes to avoid

Running Simpson's rule with an odd number of subintervals breaks the 1-4-2-4 pattern — \(n\) must be even, because each parabola spans two intervals. Misplacing the 4s: the heavy weights belong to the odd-indexed points, and a single swap silently wrecks the answer, so write the indices above the weights. Forgetting the outer factors \(\frac{h}{2}\) or \(\frac{h}{3}\) scales the entire answer; check with a known integral like \(\int_0^1 dx = 1\). Rounding sample values too early destroys accuracy that the rule worked hard to earn — keep full precision until the final step. And remember these rules deliver numbers, not antiderivatives: change the limits and the whole computation reruns.

Key takeaways

When no antiderivative exists — or none is worth finding — approximate the definite integral directly. Trapezoid rule: \(\frac{h}{2}\) times the \(1, 2, 2, \dots, 2, 1\) weights, error shrinking like \(h^2\), overestimating on concave-up stretches. Simpson's rule (\(n\) even): \(\frac{h}{3}\) times the \(1, 4, 2, 4, \dots, 4, 1\) weights, error shrinking like \(h^4\), exact for cubics. On \(\int_0^1 \frac{dx}{1+x^2}\), four subintervals gave trapezoid error \(-0.0026\) and Simpson error \(-0.000006\) from the same samples. The error bound formulas turn a target accuracy into a choice of \(n\).

Flashcards

Flashcard

h = (b − a)/n

Width of each subinterval

Equal slicing of the interval [a, b].

Test your understanding

Question 1 of 5

With h = 1, f(x₀) = 1, f(x₁) = 2, f(x₂) = 4, what does the trapezoid rule give for the integral?

Question 2 of 5

Which weight pattern does Simpson's rule use?

Question 3 of 5

Why does Simpson's rule require an even number of subintervals?

Question 4 of 5

On a stretch where the integrand is concave up, the trapezoid rule does what?

Question 5 of 5

If the trapezoid rule with n = 10 has error E, roughly what error do you expect with n = 20?

Standards: 6

← Previous topicNext topic →