Numerical Integration

Some integrands — famously \(e^{-x^2}\) — have no elementary antiderivative, so the Fundamental Theorem can't help. Instead you chop \([a,b]\) into subintervals and add up simple shapes: trapezoids, or parabola-topped panels with Simpson's Rule.

By the end you'll be able to compute Trapezoidal and Simpson estimates for a definite integral, and predict how fast each rule's error shrinks as you increase the number of subintervals.

Predict: with the Trapezoid rule selected, double n (say 4 → 8) — does the error roughly halve or quarter? Slide to check, then switch to Simpson and double n again.

The curve is \(f(x) = 1/(1+x^2)\) on \([0, 2]\), whose exact integral is \(\arctan 2 \approx 1.10715\). The shaded panels are what the rule actually adds up; hover or tab to any panel for its individual contribution. Watch the |error| readout as n grows.

Rule

T41.10385 · exact = arctan 2 ≈ 1.10715 · |error| ≈ 0.00330

f(x) = 1/(1+x²) — the rule's panels vs the true curve on [0, 2]
true curve f(x) approximation panels

When an antiderivative is unavailable, definite integrals are approximated numerically: the Trapezoidal Rule averages left/right sums and Simpson's Rule fits parabolas, both Newton–Cotes rules whose error shrinks as the number of subintervals grows.

Two rules, one recipe

Both rules start the same way: split \([a,b]\) into \(n\) equal pieces of width \(\Delta x = (b-a)/n\), sample \(f\) at the endpoints \(x_0 = a, x_1, \dots, x_n = b\), and take a weighted sum of those samples. Only the weights differ.

Visual

The Trapezoidal Rule replaces the curve on each subinterval with the straight chord joining its endpoints — you saw those flat-topped panels in the demo above hug the curve loosely. Simpson's Rule tops each pair of subintervals with a parabola through three points, and parabolas bend with the curve — at the same n the panels become nearly indistinguishable from \(f\) itself. That visual snugness is the accuracy difference.

Numerical

Trapezoid, denoted \(T_n\), uses weights \(1, 2, 2, \dots, 2, 1\) times \(\Delta x / 2\): \[T_n = \tfrac{\Delta x}{2}\big[f(x_0) + 2f(x_1) + \cdots + 2f(x_{n-1}) + f(x_n)\big].\] Simpson, denoted \(S_n\), uses weights \(1, 4, 2, 4, \dots, 4, 1\) times \(\Delta x / 3\) and needs even n: \[S_n = \tfrac{\Delta x}{3}\big[f(x_0) + 4f(x_1) + 2f(x_2) + \cdots + 4f(x_{n-1}) + f(x_n)\big].\] Their error bounds tell you how fast each converges: if \(|f''| \le M\), then \(|E_T| \le \frac{M(b-a)^3}{12 n^2}\) — doubling n cuts the error by ~4. If \(|f^{(4)}| \le M\), then \(|E_S| \le \frac{M(b-a)^5}{180 n^4}\) — doubling n cuts the error by ~16.

Applied

This is how real software integrates. The normal distribution's CDF involves \(\int e^{-x^2/2} dx\), which has no closed form — every statistics table and library routine you've ever used was computed by a rule like these. When your data is a table of sensor readings rather than a formula, numerical rules are the only option: you have samples \(f(x_i)\), and a weighted sum of samples is exactly what \(T_n\) and \(S_n\) ask for.

Worked example

Estimate \(\int_0^2 \frac{1}{1+x^2} dx\) with \(n = 4\) — the demo's default. Here \(\Delta x = 0.5\) and the samples are \(f(0)=1\), \(f(0.5)=0.8\), \(f(1)=0.5\), \(f(1.5)=0.30769\), \(f(2)=0.2\).
Trapezoid: \(T_4 = \tfrac{0.5}{2}\big[1 + 2(0.8) + 2(0.5) + 2(0.30769) + 0.2\big] = 0.25(4.41538) = \) 1.10385.
Simpson: \(S_4 = \tfrac{0.5}{3}\big[1 + 4(0.8) + 2(0.5) + 4(0.30769) + 0.2\big] = \tfrac{1}{6}(6.63077) = \) 1.10513.
The exact value is \(\arctan 2 \approx 1.10715\): Simpson's error (≈ 0.0020) already beats trapezoid's (≈ 0.0033) at the same n.

Your turn

Estimate \(\int_0^4 \sqrt{x}\, dx\) with the Trapezoidal Rule, \(n = 2\). Then \(\Delta x = 2\), and the samples are \(f(0) = 0\), \(f(2) = \sqrt{2} \approx 1.41421\), \(f(4) = 2\). Now finish it: \(T_2 = \tfrac{2}{2}\big[0 + 2(1.41421) + 2\big] = \) ____ (and is it an over- or under-estimate of the exact \(16/3 \approx 5.33333\)?)

Reveal the answer

\(T_2 = 1 \cdot (0 + 2.82843 + 2) = \) 4.82843 — an under-estimate. \(\sqrt{x}\) is concave down, so each chord sags below the curve and the trapezoids miss area. (For the concave-up curve in the demo, the chords sit above the curve — trapezoid direction of error tracks concavity.)

More info — why Simpson's Rule is exact for cubics

Fitting a parabola should only nail polynomials up to degree 2 — yet Simpson's Rule integrates any cubic exactly. The reason is symmetry: over each panel, a cubic's deviation from its interpolating parabola is an odd function about the panel's midpoint, so its integral cancels to zero. That free extra degree is why the error bound involves \(f^{(4)}\) (the first derivative that can break the symmetry) and why the error falls like \(1/n^4\) rather than \(1/n^3\). The OpenStax section in Dive deeper below states both error theorems precisely.

Check your understanding

Question 1 of 4

Use the Trapezoidal Rule with \(n = 2\) to estimate \(\int_0^2 (x^2 + 1)\,dx\).

Question 2 of 4

You compute a trapezoidal estimate with \(n = 8\), then recompute with \(n = 16\). Roughly how does the error change?

Question 3 of 4

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

Question 4 of 4

Which of these integrals genuinely forces a numerical method like Simpson's Rule, rather than an exact technique?

Recap

  • No elementary antiderivative? Sample \(f\) at \(n+1\) equally spaced points with \(\Delta x = (b-a)/n\) and take a weighted sum.
  • Trapezoid: weights \(1, 2, 2, \dots, 2, 1\) times \(\Delta x/2\); error \(\propto 1/n^2\) (doubling n cuts error ~4×).
  • Simpson: weights \(1, 4, 2, 4, \dots, 4, 1\) times \(\Delta x/3\); needs even n; error \(\propto 1/n^4\) (doubling n cuts error ~16×) and exact for cubics.
  • For smooth integrands, Simpson's Rule reaches a given accuracy with far fewer subintervals than the Trapezoidal Rule.

Dive deeper

Sources

  • Numerical Integration — Trapezoidal Rule and Simpson's Rule