Hexa Scholar

Numerical integration: trapezoid vs Simpson

A wooden slab with a curved upper edge, loose gold trapezoid blocks, and a navy caliper on a cream tabletop.
A curved slab and loose measuring pieces stand for an area assembled from simpler shapes.

The question

For the area under ex from 0 to 1, what changes when you double the number of intervals?

Choose an error reduction before the calculation opens.

  1. 1 SeePredict the effect of doubling intervals.
  2. 2 TryTest a corner and meet error goals.
  3. 3 ProveBuild the integration weights.
  4. 4 ApplyEstimate totals and choose a grid.
Before you start · 3 quick checks on integrals, curvature, and error

Two ideas before you start

2 ideas

Join neighboring samples

The exponential curve and straight segments joining its sampled heights.

A trapezoid replaces the curve between two samples by a straight segment. Change the grid to see which points are joined.

Exact definition

Let \(a\lt b\), let \(n\) be a positive integer, and set \(h=(b-a)/n\), \(x_i=a+ih\), and \(f_i=f(x_i)\). The composite trapezoid rule is

\[\begin{aligned}T_n&=h\left(\frac{f_0+f_n}{2}+\sum_{i=1}^{n-1}f_i\right).\end{aligned}\]

Each interval contributes its width times the average of its endpoint heights. An interior sample belongs to two neighboring trapezoids, so its two half-weights add. The formula also works for negative heights; it approximates signed area.

Fit a curve through each triple

The exponential curve and quadratic pieces passing through triples of samples.

Simpson's rule uses a quadratic through each consecutive triple. Each piece spans a pair of equal intervals.

Exact definition

For an even integer \(n\ge2\) on the same uniform grid, composite Simpson integration is

\[\begin{aligned}S_n&=\frac h3\bigg[f_0+f_n\\&\qquad+4\sum_{\substack{i=1\\i\text{ odd}}}^{n-1}f_i\\&\qquad+2\sum_{\substack{i=2\\i\text{ even}}}^{n-2}f_i\bigg].\end{aligned}\]

An empty sum contributes zero. The midpoint of each pair gets a different weight from its endpoints. Stage 3 derives those weights by integrating the interpolating polynomial. The even-count restriction belongs to this composite rule.

Refresher: what interpolation means

Interpolation chooses a polynomial that passes through given samples. Two distinct horizontal positions determine a line; three distinct positions determine a polynomial of degree at most two. The polynomial can have lower degree when the samples lie on a line. It need not match the curve's derivatives.

The fundamental theorem of calculus evaluates an integral through an antiderivative. Numerical integration instead uses sampled values. We use functions with known integrals here so the approximation can be checked against a reference. Real data may have measurement error as well as integration error.

1 See

Double the grid, then inspect the error

2 Try

Change the shape

A smooth curve is only one test. Make a new prediction for a curve with a corner before looking at either approximation.

3 Prove

Build Simpson's weights

Theorem

Let \(h\gt0\) and let \(m\) be real. On \([m-h,m+h]\), let \(p\) be the polynomial of degree at most two that takes the values \(f_-\), \(f_0\), and \(f_+\) at the left endpoint, midpoint, and right endpoint. Then

\[\begin{aligned}&\int_{m-h}^{m+h}p(x)\,dx\\&=\frac h3(f_-+4f_0+f_+).\end{aligned}\]

For a uniform grid with even \(n\ge2\), adding this formula over disjoint pairs gives the composite rule. This statement concerns the interpolating polynomial. It does not say an arbitrary sampled function equals that polynomial between nodes.

Use \(t=(x-m)/h\) and the three basis polynomials below. Each is one at its own node and zero at the other two:

\[\begin{aligned}L_-(t)&=(t^2-t)/2,\\L_0(t)&=1-t^2,\\L_+(t)&=(t^2+t)/2.\end{aligned}\]

Thus \(p(m+ht)=f_-L_-(t)+f_0L_0(t)+f_+L_+(t)\). These are interpolation basis polynomials, not probabilities; some values between nodes are negative.

Error guarantees and why the rates differ

Write \(I=\int_a^b f(x)\,dx\), with \(a\lt b\) and \(h=(b-a)/n\). The notation \(f\in C^k[a,b]\) means the derivatives through order \(k\) are continuous on the interval. If \(f\in C^2[a,b]\) and \(|f''|\le M_2\), then

\[|T_n-I|\le\frac{(b-a)M_2h^2}{12}.\]

The interpolation remainder on a single interval \([u,u+h]\) bounds the vertical gap by \(M_2(x-u)(u+h-x)/2\). Integrating that nonnegative bound gives \(M_2h^3/12\). Adding over all intervals gives the displayed global bound. The Taylor remainder lesson develops the same principle of replacing an unknown derivative by an upper bound.

For even \(n\), if \(f\in C^4[a,b]\) and \(|f^{(4)}|\le M_4\), the standard Simpson remainder gives

\[|S_n-I|\le\frac{(b-a)M_4h^4}{180}.\]

The local remainder on a pair is \(I_{\rm pair}-S_{\rm pair}=-h^5f^{(4)}(\xi)/90\) for some point inside that pair. Summing its absolute bound over \(n/2\) pairs proves the global bound. We use this local remainder theorem here; the weight derivation above is not a proof of it.

Simpson's rule also integrates every cubic exactly: after shifting to the midpoint, the odd cubic term integrates to zero, and its weighted symmetric samples cancel. That extra cancellation explains why the remainder uses a fourth derivative even though the fitted curve is only quadratic. Higher degree is not an unconditional accuracy ranking.

Another choice: move the nodes

Trapezoid and Simpson rules use equally spaced samples, which is convenient when a sensor already supplied them. Gaussian quadrature chooses the sample locations as well as their weights. The two-node Gauss rule on \([-1,1]\) samples at \(\pm1/\sqrt3\), gives each sample weight one, and integrates every polynomial of degree at most three exactly.

To check that claim, apply it to the constant, linear, quadratic, and cubic terms separately. Symmetry handles the odd terms. For the quadratic, the two squared node values add to the exact quadratic integral. This is a different sampling plan, not a way to reweight arbitrary existing data. Mapping another interval to this one multiplies the weights by half its length.

4 Apply

Estimate a total and choose a grid

Use the formulas above. Enter a number in each box. A tolerance is shown for approximate answers; the interval count must be a whole number. Each question includes hints and a worked solution.

Key point Count intervals separately from nodes. Keep the step width in the units of the horizontal axis, use the right endpoint weights, and distinguish an estimate of a total from a guaranteed bound on its error.
Level IntroPrerequisites definite integrals, derivatives, and the interpolation refresher aboveTime ~35 min

Further reading