Skip to content
Tutorials Center
My learning

Topics

Lesson 37 of 37 · Projects and Practice

Project: Quadrature Error Analysis

Use the mean value theorem and Taylor's theorem to prove error bounds for the rectangle, midpoint and trapezoid rules, then verify the predicted convergence orders in code.

When you cannot find an antiderivative, you approximate an integral by a sum. Real analysis tells you how large the error can be, and how fast it shrinks. In this project you prove error bounds for three rules, then test them on integrals whose exact values are known. It brings together the Riemann integral, the Mean Value Theorem and Taylor's theorem.

The rules

Split [a, b] into n equal pieces of width h = (b - a)/n with points xᵢ = a + i h.

Rule Approximation of ∫ₐᵇ f
Left rectangle h Σ_{i=0}^{n-1} f(xᵢ)
Midpoint h Σ_{i=0}^{n-1} f(xᵢ + h/2)
Trapezoid h ( f(a)/2 + Σ_{i=1}^{n-1} f(xᵢ) + f(b)/2 )

All are Riemann sums, so for continuous f they converge to the integral. The question is how fast.

Error of the left rectangle rule

Suppose |f'| ≤ K₁ on [a, b]. On one piece [xᵢ, xᵢ + h], the MVT gives |f(t) - f(xᵢ)| ≤ K₁ (t - xᵢ), so

Text
| ∫_{xᵢ}^{xᵢ+h} f - h f(xᵢ) | ≤ K₁ ∫₀ʰ s ds = K₁ h²/2.

Summing over n pieces: total error ≤ n K₁ h²/2 = K₁ (b - a) h / 2. The error is O(h): halving h halves the error bound.

Error of the midpoint rule

Let m = xᵢ + h/2, and suppose |f''| ≤ K₂. Taylor with remainder at m: f(t) = f(m) + f'(m)(t - m) + f''(ξ)(t - m)²/2. Integrate over [m - h/2, m + h/2]; the linear term integrates to 0 by symmetry, so

Text
| ∫ f - h f(m) | ≤ K₂/2 ∫_{-h/2}^{h/2} s² ds = K₂ h³ / 24.

Summing: error ≤ K₂ (b - a) h² / 24. That is O(h²).

Error of the trapezoid rule

On one piece the trapezoid is the integral of the linear interpolant p of f at the endpoints. A standard Taylor/Rolle argument shows f(t) - p(t) = f''(ξₜ)(t - xᵢ)(t - xᵢ - h)/2. With |f''| ≤ K₂,

Text
| ∫ (f - p) | ≤ K₂/2 ∫₀ʰ s (h - s) ds = K₂ h³ / 12,

so the total error is at most K₂ (b - a) h² / 12, also O(h²), with a constant twice as large as the midpoint rule's bound.

Python Observed convergence orders

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Ratios near 2 for the left rule and near 4 for the other two confirm the orders O(h) and O(h²).

Checking the rigorous bounds

For f(x) = sin x on [0, 2]: |f'| ≤ 1, |f''| ≤ 1. The bounds are (b - a)h/2 = h for left, 2h²/24 = h²/12 for midpoint and 2h²/12 = h²/6 for trapezoid. The actual errors must lie under these.

Python Actual error versus proven bound

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

When the assumptions fail

The bounds need f' or f'' bounded. For f(x) = √x on [0, 1], f' is unbounded near 0 and the observed orders degrade. Test this yourself: modify the program above with f = math.sqrt, exact = 2/3, and compare ratios; the ratios for both the trapezoid and midpoint rules fall to about 2.8 (the error now shrinks like h^1.5) instead of 4. The failure is not a flaw in the theory; it is the theory telling you which hypothesis was needed.

Extensions

  1. Prove the error bound for Simpson's rule, O(h⁴) with a bound involving |f⁗|.
  2. Use Richardson extrapolation: combine the trapezoid results at n and 2n as (4T₂ₙ - Tₙ)/3 to cancel the leading error term (you will have rediscovered Simpson's rule).
  3. Choose n automatically so the proven bound is below a target tolerance.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. The left rectangle rule error (for a function with bounded derivative) shrinks like:

    The MVT bound gives total error at most K1 (b - a) h / 2.
  2. 2. For the midpoint rule, why does the linear Taylor term disappear?

    The integral of (t - m) over [m - h/2, m + h/2] is 0.
  3. 3. If you double n for a second-order rule, the error bound is divided by about:

    The bound is proportional to h squared and h is halved.
  4. 4. Which hypothesis did the h^2 bounds for midpoint and trapezoid rules use?

    The constant K2 in the bounds is a bound for |f''|.

Summary

  • Left rectangle: error ≤ K₁(b - a)h/2 (order h), from the MVT.
  • Midpoint: error ≤ K₂(b - a)h²/24; trapezoid: error ≤ K₂(b - a)h²/12 (order h²), from Taylor's theorem.
  • Numerical experiments confirm the orders: error ratios near 2 for first-order, near 4 for second-order rules when n doubles.
  • Bounds depend on smoothness hypotheses; with unbounded derivatives the observed rates degrade.

Next: Back to the Real Analysis track