What is the Simpson's Rule Integration Calculator?
This tool numerically approximates the definite integral of a function f(x) over an interval [a, b] using the composite Simpson's rule. It is pure mathematics and applies universally. The calculator refines its estimate by doubling the number of subintervals (2, 4, 8, 16, ... up to a chosen maximum N), letting you watch the value converge.
How to use it
Enter your function in terms of x (for example 4/(1+x^2) or sin(x)), set the lower bound a and upper bound b, and choose the maximum number of subdivisions N. You may also pick how many significant digits to display. Both the bounds and the function accept constants like pi and e as well as functions sin, cos, tan, exp, ln, log10, sqrt, abs and more.
The formula explained
For an even number of subintervals \(n\) over [a, b], the step size is \(h = (b - a) / n\). With nodes \(x_i = a + i\cdot h\), Simpson's rule weights the endpoints by 1, interior odd-indexed nodes by 4, and interior even-indexed nodes by 2, then multiplies the total by \(h/3\).
$$\int_{a}^{b} f(x)\,dx \approx \frac{h}{3}\left[ f(x_0) + 4\sum_{i\,\text{odd}} f(x_i) + 2\sum_{i\,\text{even}} f(x_i) + f(x_N) \right]$$The method has error \(O(h^4)\) and is exact for polynomials of degree three or less.
Worked example
Take \(f(x) = 4/(1+x^2)\), \(a = 0\), \(b = 1\), \(n = 4\). Then \(h = 0.25\) and the node values are 4.000000, 3.764706, 3.200000, 2.560000, 2.000000. Applying Simpson's rule:
$$S = \frac{0.25}{3}\cdot\left[4 + 4\cdot(3.764706 + 2.560000) + 2\cdot 3.200000 + 2\right] = 3.141569$$With \(N = 64\) the estimate converges to \(\pi \approx 3.14159265358979\).
FAQ
Why must n be even? Simpson's rule pairs adjacent subintervals to fit a parabola through three points, so the count must be even. The powers of two used here are always even.
What if b is less than a? The result is simply the negative of the integral over [b, a]; the formula handles a negative step size correctly.
What about singularities? If f(x) is undefined at a node (division by zero, log of a non-positive number, sqrt of a negative), the result becomes unreliable; the calculator reports an error instead of a misleading number.