Understanding the Simpson's rule integration calculator — concept and principle
A definite integral ∫ₐᵇ f(x) dx measures the signed area between a curve and the x-axis from x = a to x = b. This calculator estimates it numerically for a polynomial with Simpson's rule and the trapezoidal rule, and also shows the exact value from the antiderivative so you can see how accurate each method is. Numerical methods are how computers integrate measured data and functions with no closed-form antiderivative.
How it is calculated
Split [a, b] into N equal intervals of width h = (b − a) ÷ N and let fᵢ = f(a + i·h).
- Simpson's rule: (h/3)[f₀ + 4f₁ + 2f₂ + 4f₃ + … + 4fₙ₋₁ + fₙ]. N must be even; an odd entry is rounded to an even number.
- Trapezoidal rule: h[f₀/2 + f₁ + f₂ + … + fₙ₋₁ + fₙ/2].
- Exact value: F(b) − F(a), where F is the antiderivative obtained by the power rule ∫xⁿ dx = xⁿ⁺¹ ÷ (n + 1).
Coefficients are entered from the highest power down, so "1 0 0" is f(x) = x².
The principle
The trapezoidal rule joins neighbouring points with straight lines and adds up the trapezoids. Simpson's rule fits a parabola through every three consecutive points and integrates the parabolas exactly; the weights 1, 4, 1 (times h/3) come from that parabola's area. Because a parabola matches curvature, Simpson's error shrinks like h⁴, while the trapezoid error shrinks only like h². Simpson's rule is exact for every polynomial of degree 3 or less.
Worked example
- Default inputs: f(x) = x², a = 0, b = 3, N = 100, so h = 0.03.
- Exact: F(x) = x³/3, so F(3) − F(0) = 27/3 = 9.
- Simpson: x² has degree 2, so the rule is exact and gives 9.
- Trapezoid: its error for a smooth f is (b − a)h²f″ ÷ 12 = 3 × 0.0009 × 2 ÷ 12 = 0.00045, so the result is 9.00045.
| From a | Simpson |
|---|---|
| 0 | 9 |
| 1 | 8.666666667 |
| 2 | 6.333333333 |
| 3 | 0 |
| 4 | -12.33333333 |
| 5 | -32.66666667 |
| 6 | -63 |
How to read the result
Compare the numerical results with the exact value. If Simpson and the exact value agree to many digits, the interval count is ample. The trapezoid result overestimates when the curve bends upward (f″ > 0) and underestimates when it bends downward. Doubling N cuts the trapezoid error by about 4 and the Simpson error by about 16. A negative result means more area lies below the x-axis than above it.
Common mistakes
- Forgetting zero coefficients: x² is 1 0 0, not 1.
- Using Simpson's rule with an odd number of intervals.
- Treating the signed integral as the total geometric area when the curve crosses the axis.
Frequently asked questions
Why is Simpson's rule exact for cubics even though it fits parabolas?
The error of the cubic term cancels by symmetry over each pair of intervals, so the leading error depends on the fourth derivative, which is zero for cubics.
How many intervals should I use?
Increase N until the result stops changing in the digits you care about.
What is Simpson's 3/8 rule?
A variant that fits cubics through four points with weights 1, 3, 3, 1 and factor 3h/8; it needs N divisible by 3.
Sources: Burden, R. L., Faires, J. D., Numerical Analysis, Chapter 4: Numerical Differentiation and Integration · NIST Digital Library of Mathematical Functions, §3.5 Quadrature (dlmf.nist.gov)