Connect via MCP →

Enter Calculation

Formula

Advertisement

Results

S = ∫ab f(x) dx (approximation)
3.1415519635
composite trapezoidal rule
n (subintervals) S(n)
2 3.100000000000
4 3.131176470588
8 3.138988494491
16 3.140941612041
32 3.141429893175
64 3.141551963486

What this calculator does

This tool approximates the definite integral of a function f(x) over a finite interval [a, b] using the composite trapezoidal rule. It works for any analytic, non-periodic integrand and is universal mathematics — the result does not depend on units, currency, or country. You supply the function, the lower and upper bounds, and the maximum number of subintervals; the calculator refines the estimate by repeatedly doubling the subdivision count and shows the converging sequence.

How to use it

Type your function in terms of x — operators + - * /, powers (^ or **), and functions such as sin, cos, tan, exp, log (natural), ln, sqrt, abs, plus the constants pi and e are supported. Enter the bounds a and b (any real numbers; if a > b the sign is handled automatically). Pick the maximum number of subdivisions N (a power of two from 32 to 2048). The reported answer S is the trapezoidal value at the largest N.

The formula explained

Split [a, b] into n equal pieces of width \(h = (b - a) / n\). The trapezoidal rule replaces the curve on each piece with a straight line, summing the areas of the resulting trapezoids:

$$\int_{a}^{b} f(x)\,dx \approx \frac{h}{2}\left[ f(x_0) + 2\sum_{i=1}^{N-1} f(x_i) + f(x_N) \right]$$

\(S(n) = \frac{h}{2} \cdot \left[ f(a) + 2\cdot(f(a+h) + f(a+2h) + \cdots + f(a+(n-1)h)) + f(b) \right]\). The endpoints are weighted once and every interior node twice. The error shrinks like \(O(h^2)\), so doubling n cuts the error roughly fourfold for smooth functions.

Advertisement
Area under a curve approximated by adjacent trapezoidal strips between bounds a and b
The composite trapezoidal rule sums the areas of equal-width trapezoids under the curve.

Worked example

Take \(f(x) = \frac{4}{1+x^2}\) on [0, 1], whose exact value is \(\pi\). With \(n = 2\), \(h = 0.5\): \(f(0)=4\), \(f(0.5)=3.2\), \(f(1)=2\), so $$S = 0.25\cdot(4 + 2\cdot3.2 + 2) = 3.1.$$ With \(n = 4\) you get 3.131176, \(n = 8\) gives 3.138988, and at \(n = 64\) the value is about 3.141552 — closing in on \(\pi = 3.14159265\ldots\)

Coarse versus fine trapezoidal subdivisions showing better fit with more strips
Increasing the number of subdivisions n shrinks the gap between the chords and the true curve.

FAQ

Why is my result slightly off? The trapezoidal rule is approximate. Increase N for more accuracy; the convergence table shows how fast it settles.

Can I integrate periodic or singular functions? The method assumes a smooth, non-periodic integrand. For singularities at the endpoints or interior the result may be wrong or undefined — use a dedicated method instead.

What if a equals b? The integral over a zero-width interval is 0, which the calculator returns directly.

Last updated: