Numerical Integration
Simpson’s rule against the midpoint and trapezoidal rules, with the error order each one actually achieves.
n = 10 · reference 0.78539816 · error 9.913e-9
| Method | Estimate | Error | Order |
|---|---|---|---|
| Midpoint rule | 0.7856065 | 2.08e-4 | O(h²) |
| Trapezoidal rule | 0.7849815 | 4.17e-4 | O(h²) |
| Simpson’s rule | 0.78539815 | 9.91e-9 | O(h⁴) |
Midpoint rule: 4.0× · Trapezoidal rule: 4.0× · Simpson’s rule: 63.9×
A second-order method should improve by about 4× and a fourth-order one by about 16×. A ratio well below that usually means the integrand is not smooth enough for the order to hold.
Simpson’s rule fits a parabola through every pair of subintervals instead of a straight line, which makes it dramatically more accurate than the trapezoidal rule for the same work. Its error falls as h⁴, so halving the step size cuts the error roughly sixteen-fold.
Straight lines against parabolas
The trapezoidal rule joins consecutive sample points with a straight line and sums the trapezoids. Simpson’s rule takes them three at a time and fits a parabola through each triple, integrating that exactly. Since a parabola can follow a curve far better than a chord, the same number of function evaluations buys much more accuracy.
The surprising consequence is that Simpson’s rule integrates cubics exactly, even though it only fits quadratics. The cubic part of the error cancels by symmetry across each pair of intervals, which is why the leading error term involves the fourth derivative rather than the third — and why the tool reports “exact for this integrand” rather than a convergence ratio when you give it a polynomial of degree three or less.
What the order actually means
A method of order p has error proportional to hᵖ, where h is the step size. Doubling the number of subintervals halves h, so a second-order method should improve by about 4× and a fourth-order one by about 16×. Watching that ratio is the practical way to check a method is behaving — if Simpson’s rule is only improving fourfold, the integrand is not smooth enough for its order to hold.
Simpson’s rule; the 4s and 2s alternate on interior points and n must be even
- 1 Choose an even number of subintervals. Simpson pairs them up, so n must be even; the tool rounds an odd n up for you.
- 2 Find the step size. For [0, 1] with n = 10, h = 0.1.
- 3 Evaluate the function at every node. At x = 0, 0.1, 0.2, … 1.0 — eleven points for ten intervals.
- 4 Weight them 1, 4, 2, 4, 2, … 4, 1. The endpoints get 1, odd-indexed points get 4 and even-indexed interior points get 2.
- 5 Multiply the total by h ÷ 3. For 1/(1 + x²) on [0, 1] this gives 0.78539815, against the true π/4 = 0.78539816.
Error order by method
h is the step size. The right-hand column is what doubling the number of subintervals should do.
| Method | Error order | Improvement when n doubles |
|---|---|---|
| Left or right rectangles | O(h) | About 2× |
| Trapezoidal rule | O(h²) | About 4× |
| Midpoint rule | O(h²) | About 4×, with a smaller constant |
| Simpson’s rule | O(h⁴) | About 16× |
When the order stops holding
Every one of these orders assumes the integrand is smooth enough — Simpson’s h⁴ result requires a bounded fourth derivative across the interval. Give it √x on [0, 1], whose derivative blows up at the origin, and all three methods degrade to roughly 2.8× improvement per doubling instead of 4× and 16×. The tool prints the observed ratio precisely so that this failure is visible rather than hidden behind a plausible-looking number.
The same caveat applies to the reference value the errors are measured against. It is Simpson’s rule at 20,000 intervals — extremely accurate for a smooth function, but for an integrand with an endpoint singularity it carries error of its own, so a reported error below about 1e−8 on such a function should be read as “at the limit of this method” rather than as a precise figure. Singular or oscillatory integrands need adaptive quadrature or a substitution, not more subintervals.