Trapezoidal Rule Calculator
Inputs
| Lower limit | 0 |
|---|---|
| Upper limit | 1 |
| Subintervals | 4 |
| Function values | 1, 0.94, 0.78, 0.64, 0.5 |
Trapezoidal Rule Calculator
Approximate a definite integral with the trapezoidal rule from sampled function values. Enter the limits, the number of subintervals, and the values f(x₀)…f(xₙ) to get the area estimate and the step size.
Inputs
Results
Enter a value to see results.
The trapezoidal rule
The trapezoidal rule estimates a definite integral by replacing the curve with straight line segments between sampled points. Each strip becomes a trapezoid, and the integral is approximated by the total area of those trapezoids.
Split the interval [a, b] into n equal subintervals of width h = (b − a) / n. This creates n + 1 grid points x₀ = a, x₁, x₂, …, xₙ = b. Sampling the function at each point gives the values f(x₀), f(x₁), …, f(xₙ), and the estimate is:
∫ₐᵇ f(x) dx ≈ (h/2)·[f(x₀) + 2f(x₁) + 2f(x₂) + … + 2f(xₙ₋₁) + f(xₙ)]
This calculator works from sampled function values rather than a typed formula: you provide f at the n + 1 evenly spaced points, which is exactly the situation you face when the data comes from measurements or a table.
Why the weights are 1, 2, 2, …, 2, 1
A single subinterval [xᵢ, xᵢ₊₁] forms a trapezoid with parallel sides f(xᵢ) and f(xᵢ₊₁) and width h. Its area is (h/2)·(f(xᵢ) + f(xᵢ₊₁)). Adding the areas of all n trapezoids:
(h/2)·(f₀ + f₁) + (h/2)·(f₁ + f₂) + … + (h/2)·(fₙ₋₁ + fₙ)
Every interior point is shared by two neighbouring trapezoids, so it appears twice, while the two outer endpoints appear only once. Collecting terms produces the weight pattern 1, 2, 2, …, 2, 1, all multiplied by h/2. A convenient rearrangement, used internally, is
∫ₐᵇ f(x) dx ≈ (h/2)·[2·(f₀ + f₁ + … + fₙ) − f₀ − fₙ]
which adds every value twice and then subtracts the endpoints once.
Worked example
Estimate ∫₀¹ x² dx using n = 4 subintervals. The step size is h = (1 − 0) / 4 = 0.25, and the grid points are 0, 0.25, 0.5, 0.75, 1. The sampled values of x² are:
| x | 0 | 0.25 | 0.5 | 0.75 | 1 |
|---|---|---|---|---|---|
| f(x) = x² | 0 | 0.0625 | 0.25 | 0.5625 | 1 |
Apply the rule:
∫ ≈ (0.25/2)·[0 + 2(0.0625) + 2(0.25) + 2(0.5625) + 1] ∫ ≈ 0.125·[0 + 0.125 + 0.5 + 1.125 + 1] = 0.125·2.75 = 0.34375
The exact value is 1/3 ≈ 0.33333, so four strips already land within about 0.01. Refining to n = 10 gives 0.335, and n = 100 gives 0.333325 — the error falls roughly in proportion to h².
How the error behaves
The trapezoidal rule is second-order accurate: halving h cuts the error by about a factor of four. For a twice-differentiable function, the error over [a, b] is
E = −((b − a)·h²/12)·f″(ξ)
for some point ξ in the interval. Two consequences follow from the sign of the second derivative:
- On a concave-up curve (f″ > 0) the straight chords sit above the curve, so the rule overestimates the integral.
- On a concave-down curve (f″ < 0) the chords sit below the curve, so the rule underestimates it.
For straight lines f″ = 0, so the trapezoidal rule is exact — every strip is a true trapezoid with no curvature to miss.
Trapezoidal rule versus Simpson's rule
Simpson's rule fits a parabola through each pair of subintervals instead of a straight line. Its error is proportional to h⁴, so for smooth functions it converges far faster than the trapezoidal rule for the same number of points. The trade-off is that Simpson's rule requires an even number of subintervals, whereas the trapezoidal rule works with any n. The trapezoidal rule is also more robust for noisy or irregular data, where forcing a parabola through scattered points can amplify the noise.
A practical rule of thumb: use the trapezoidal rule for quick estimates, tabulated data, or when n must be odd; reach for Simpson's rule when the function is smooth and you want high accuracy for the same sampling effort.
Practical notes
- Match the count. With n subintervals you must supply exactly n + 1 values, one per grid point. The calculator flags a mismatch so the spacing stays uniform.
- Keep the order. List values from x₀ = a to xₙ = b. The endpoints are weighted differently from the interior, so the order matters.
- Reversed limits. If a is greater than b, the step size is negative and the result changes sign — matching the convention that swapping integration limits negates the integral.
- Equal spacing only. This is the uniform-grid trapezoidal rule. Unequally spaced data needs the general trapezoidal formula with per-strip widths.
Related calculators
- Definite Integral of Polynomial Calculator — exact integral of a polynomial via the fundamental theorem of calculus
- Polynomial Derivative Calculator — numerical derivative at a single point
- Arithmetic Sequence Calculator — terms and sums of evenly spaced values
Frequently Asked Questions (FAQ)
How many function values do I need to enter?
Dividing the interval [a, b] into n subintervals creates n + 1 grid points: x₀ = a, x₁, x₂, …, xₙ = b. You enter the function value at each of those points, so n subintervals require n + 1 values. For example, 4 subintervals over [0, 1] use the points 0, 0.25, 0.5, 0.75, 1 — five values in total. If your value count and subinterval count do not match, the calculator flags it so the spacing stays consistent.
Why are the endpoints counted once but the interior points twice?
Each subinterval contributes one trapezoid whose area is (h/2)(left height + right height). Adjacent trapezoids share an interior grid point, so its height appears in two trapezoids and is added twice. The two outer endpoints x₀ and xₙ belong to only one trapezoid each, so they are counted once. Collecting the terms gives the familiar weights 1, 2, 2, …, 2, 1, all multiplied by h/2.
How accurate is the trapezoidal rule compared with Simpson’s rule?
The trapezoidal rule approximates the curve between points with straight line segments, so its error shrinks proportionally to h² (it is second-order accurate). It is exact for straight lines but overestimates concave-down curves and underestimates concave-up curves.
Simpson’s rule fits parabolas through pairs of subintervals and has error proportional to h⁴, so for smooth functions it is usually far more accurate for the same number of points. Use more subintervals to drive the trapezoidal error down, or switch to Simpson’s rule when high accuracy matters.
What if the lower limit is larger than the upper limit?
If a is greater than b, the step size h = (b − a) / n is negative, which flips the sign of the result — consistent with the convention that swapping the limits of an integral negates it. The magnitude of the estimate is unchanged. List the function values in order from x₀ = a to xₙ = b so the pairing with the grid points stays correct.
Recommended Next
Definite Integral of Polynomial Calculator
Compute the exact definite integral ∫_a^b P(x) dx for any polynomial using the Fundamental Theorem of Calculus — exact result, no approximation.