Lite / Engineering Complex Systems / 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?
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.
Predict
You integrate a smooth curve with the trapezoid rule, then halve the step size. Roughly what happens to the error?
- It halves
- It falls to about a quarter
- It stays the same
- It doubles
Guess first, then reveal
Trapezoid error ∝ h², so halving h divides the error by about 4. Left and right rectangle sums only halve their error. That is why trapezoids are the default for sampled data.
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.
What the interactive shows (text version)
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.
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
Intuitive
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.
Technical
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.
Mathematical
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²).
Applied
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.
Practice
Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.
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?
Reflect
How would you choose a logging interval for a power trace if you wanted the energy to within 1%?
Write your answer on paper or in your own notes. Lite never stores what you write.