What this calculator does
This tool approximates the definite integral of a function f(x) over a finite interval [a, b] using three classic composite quadrature rules: the Trapezoidal Rule, the Midpoint Rule, and Simpson's Rule. Instead of returning a single number, it evaluates each rule at subdivision counts of 2, 4, 8, 16, ... doubling each time up to your chosen maximum N, and prints a convergence table so you can watch the estimates stabilize and judge accuracy yourself.
How to use it
Enter the integrand as a math expression in the variable x (for example 4/(1+x^2) or sin(x)*exp(-x)). Supported operators are + - * / ^ with parentheses, plus common functions such as sin, cos, tan, exp, log/ln, sqrt and abs, and the constants pi and e. Set the lower limit a and upper limit b, choose the maximum number of subdivisions N (a power of two), and pick how many display digits to show. The headline figure is Simpson's estimate at \(n = N\), since it usually converges fastest.
The formulas explained
For n subintervals the step is \(h = (b - a)/n\) and the nodes are \(x_i = a + i\,h\). The Trapezoidal rule sums function values weighting the two endpoints by half. The Midpoint rule samples the center of each subinterval. Simpson's rule blends them with weights 1, 4, 2, 4, ..., 4, 1 and is exact for cubics, giving error of order \(h^4\) versus \(h^2\) for the other two.
$$\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]$$where
$$\left\{ \begin{aligned} f(x) &= \text{f(x)} \\ a &= \text{Lower limit} \\ b &= \text{Upper limit} \\ N &= \text{Subdivisions} \\ h &= \frac{b-a}{N}, \quad x_i = a + i\,h \end{aligned} \right.$$
Worked example
For \(f(x) = 4/(1+x^2)\) on [0, 1] the exact integral is \(\pi = 3.14159265\ldots\) With \(n = 4\) and \(h = 0.25\), the Trapezoidal estimate is about 3.131176, the Midpoint estimate about 3.146801, and Simpson's about 3.141569 — already accurate to five decimals. As n increases all three approach \(\pi\).
FAQ
Why must N be a power of two? Doubling subdivisions lets you compare successive rows easily and guarantees an even count for Simpson's rule.
What functions are out of scope? The convergence display assumes a smooth (analytic), non-periodic integrand. Functions with singularities inside [a, b], such as \(1/x\) across zero, will produce infinities or garbage.
What if a equals b, or a is greater than b? If \(a = b\) the integral is 0. If \(a > b\) the result is the signed (negative) value of the integral over [b, a].