School/□ Systems Engineer/Week 7
The trapezoid rule and its error
Replace rectangles with sloped tops and the error drops by a factor of four every time you halve the step. Why four, and when does it overshoot?
About 40 min · 3 goals · Checked by automated tests
1.Why should I care?
Real data arrive as samples, and the trapezoid rule is the standard way to integrate them: logged power, flow, speed. Knowing its error lets you choose a sample rate before collecting data, rather than discovering afterwards that it was too slow.
- ◇ Apply the trapezoid rule to a function and to equally spaced samples.
- ◇ Show that the trapezoid error is proportional to h² and predict it from f″.
- ◇ Decide whether a trapezoid estimate is too high or too low from the curve's concavity.
2.Discover
Choose the drone climb rate and the trapezoid rule. Step n through 1, 2, 4, 8, 16 and watch the error ratio in the readout settle near 4. Is the trapezoid estimate above or below the exact value? Look at the curve's shape to explain it.
Loading the interactive…
Can't use the interactive? Read a description instead
With the trapezoid rule on the drone climb rate, the estimate is 15 m at n = 4 against an exact 14.667 m, and each doubling of n divides the error by about 4. The estimate is always slightly high because the curve bends upwards.
3.Checkpoint: guided practice
Check what you just discovered before going on. Hints appear after a wrong answer.
Practice 1 · a fresh version every time
A robot's power draw was logged every 10 s: 8, 15, 15, 4, 8, 10 W. Estimate the energy used over the log with the trapezoid rule, in joules.
4.Predict
You integrate a smooth curve with the trapezoid rule, then halve the step size. Roughly what happens to the error?
Guess first. Being wrong here is how the surprise works.
5.Understand
The rule
Join neighbouring samples with straight lines and add the trapezoids: T = h·(y₀/2 + y₁ + y₂ + … + yₙ₋₁ + yₙ/2). End samples count half, inner samples fully. It is the average of the left and right sums.
Error and concavity
Error ≈ (b − a)·h²·f″/12. For a curve that bends upwards (f″ > 0, convex) the straight tops lie above it: the trapezoid overestimates. For a curve bending down it underestimates. For a straight line it is exact.
Choosing a sample rate
If you know roughly how sharply a signal bends (f″), the formula tells you the step needed for a target accuracy before you log anything. If you do not, integrate with h and with h/2: the difference is about three-quarters of the error of the coarser estimate, a check you can run on any data.
Explain it another way
Rectangles have flat tops that miss the curve on one side of every strip. Trapezoids tilt their tops to touch the curve at both ends, so they only miss where the curve bends.
Composite trapezoid: E_T ≈ −(b − a)h²f″(ξ)/12 (sign: exact minus estimate). Richardson extrapolation (4T_{h/2} − T_h)/3 cancels the h² term; it equals Simpson's rule.
Since T = (L + R)/2 and L, R have errors ∓½h·[f(b) − f(a)] + O(h²), the first-order errors cancel, leaving O(h²).
Pharmacologists integrate blood-concentration samples with the trapezoid rule to get a drug's 'area under the curve', and battery test rigs integrate sampled current the same way.
Derivation: Where the h² error comes from
Take one strip of f(x) = x² on [0, h] (any smooth curve looks like a parabola up close).
Trapezoid: h × (f(0) + f(h))/2 = h × (0 + h²)/2 = h³/2.
Exact: ∫₀ʰ x² dx = h³/3. Error per strip: h³/2 − h³/3 = h³/6.
For a general curve the per-strip error is about (h³/12)·f″; here f″ = 2, giving h³/6 as found.
An interval of length L has n = L/h strips, so the total error ≈ (L/h)·(h³/12)·f″ = L·h²·f″/12.
Halve h: the error falls to a quarter. Check: v = 0.5t² + 1 (f″ = 1) on [0, 4] with h = 1 gives 4 × 1 × 1/12 = 0.333 m; the trapezoid sum is 15 m against 14.667 m exact.
Worked example 1
Trapezoid rule for v = 0.5t² + 1 on [0, 4] with h = 1.
Samples 1, 1.5, 3, 5.5, 9. T = 1 × (0.5 + 1.5 + 3 + 5.5 + 4.5) = 15 m. Exact 14.667 m; error 0.333 m, matching (b − a)h²f″/12 = 4 × 1 × 1/12.
Common mix-ups
- The trapezoid rule is just a slightly better rectangle rule.
✓ It is a whole order better: error ∝ h², not h. - Error estimates need the exact answer.
✓ Comparing T_h and T_{h/2} estimates the error from the data alone.
6.Practice on your own
Practice, not a test. Wrong answers get a hint and another try.
Practice 2
Trapezoid rule for v = 0.5t² + 1 m/s on [0, 4] with h = 1 s, in metres.
Practice 3
Predict the trapezoid error for the same integral with h = 0.5 s, in metres, using (b − a)h²f″/12 (f″ = 1).
Practice 4
The trapezoid rule is applied to a curve that bends upwards (convex). The estimate is…
Practice 5 · a fresh version every time
A robot's power draw was logged every 30 s: 0, 10, 8, 5, 5, 2, 0 W. Estimate the energy used over the log with the trapezoid rule, in joules.
7.Apply it
Integrate sin t from 0 to π (exact answer 2) with the trapezoid rule using 2, 4 and 8 strips by hand or in a spreadsheet. Confirm the error ratios are near 4, then combine two estimates with (4T_{h/2} − T_h)/3. How close is it?
8.Reflect
Concepts: Numerical integration and differentiation · Integrals and accumulation