What is the Trapezoidal Rule?
The trapezoidal rule is a numerical integration method that approximates the area under a curve by dividing the interval into n equal subintervals and treating each slice as a trapezoid. By summing the areas of all these trapezoids, you get an estimate of the definite integral \(\int_{a}^{b} f(x)\,dx\) — useful when an antiderivative is hard or impossible to find in closed form.
How to use this calculator
Enter your function using x as the variable (for example x^2, sin(x), or exp(x)), then set the lower limit a, the upper limit b, and the number of subintervals n. A larger n generally produces a more accurate result. The calculator returns the approximate integral along with the step size Δx and the endpoint values.
The formula explained
The composite trapezoidal rule is:
$$\int_{a}^{b} f(x)\,dx \approx \frac{\Delta x}{2}\left[ f_0 + 2(f_1 + \cdots + f_{n-1}) + f_n \right], \quad \text{where } \Delta x = \frac{b - a}{n}.$$The endpoints \(f_0\) and \(f_n\) are counted once, while every interior point is counted twice because it is shared between two adjacent trapezoids.
Worked example
Approximate \(\int_{0}^{1} x^2\,dx\) with \(n = 10\). Here \(\Delta x = 0.1\). Summing f at the nodes gives the trapezoidal estimate \(0.335\), compared with the exact value \(\tfrac{1}{3} \approx 0.3333\). Increasing n shrinks the error, which scales roughly with \(\Delta x^2\).
FAQ
Why is my answer slightly off from the exact integral? The trapezoidal rule is an approximation; its error decreases as you increase the number of subintervals n.
What functions are supported? Polynomials and operators + - * / ^, plus sin, cos, tan, exp, ln, log, sqrt, abs, and the constants pi and e.
Can a and b be in any order? If a > b the result will simply have the opposite sign, consistent with the orientation of the integral.