Connect via MCP →

Enter Calculation

Formula

Advertisement

Results

Simpson's rule result (n = 64)
3.1415926535892149
approximation of the definite integral
Trapezoidal rule
3.1415519634856541
Midpoint rule
3.1416129986418473
Simpson's rule
3.1415926535892149
n Trapezoidal Midpoint Simpson
2 3.1000000000000001 3.1623529411764704 3.1333333333333333
4 3.1311764705882354 3.1468005183939427 3.1415686274509804
8 3.1389884944910889 3.1428947295916889 3.1415925024587068
16 3.1409416120413889 3.1419181743085600 3.1415926512248218
32 3.1414298931749749 3.1416740337963374 3.1415926535528360
64 3.1415519634856541 3.1416129986418473 3.1415926535892149

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.

Area under a curve approximated by vertical strips between a and b
Numerical integration estimates the area under f(x) from a to b by summing simple strips.

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.$$
Three panels comparing trapezoidal, midpoint and Simpson strip shapes under a curve
The three rules differ in how each strip approximates the curve: straight chord, flat midpoint rectangle, and fitted parabola.

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].

Last updated: