Calculatorism

Trapezoidal Rule — Numerical Integration

Enter [a, b] and subintervals n to estimate ∫f(x)dx by the trapezoidal rule for f(x)=p₀+p₁x+p₂x²+p₃x³, with per-trapezoid areas.

Input Data

Integral lower bound a.
Integral upper bound b (b>a).
Number of trapezoids.
Constant term.
Linear coefficient.
Quadratic coefficient (default 1 → x²).
Cubic coefficient.

Results

Trapezoidal estimate.
2.75
Exact polynomial integral (reference).
2.666667
Estimate − exact.
0.083333
Per-trapezoid area summary.
h=0.5,共 4 個梯形;前4個面積:[0,0.5]:0.0625,[0.5,1]:0.3125,[1,1.5]:0.8125,[1.5,2]:1.5625。

At a glance:The trapezoidal rule splits [a,b] into n equal subintervals of width h=(b−a)/n and approximates each by a trapezoid: ∫≈(h/2)[f(x₀)+2Σf(xᵢ)+f(xₙ)]. For polynomials this tool also gives the analytic integral to compare the error.

Formula

h = (b − a) / n.

Estimate = (h/2)[f(x₀) + 2f(x₁) + … + 2f(x_{n−1}) + f(xₙ)].

One trapezoid area = h·(f(xᵢ)+f(xᵢ₊₁))/2.

Exact (poly): ∫(p₀+p₁x+p₂x²+p₃x³)dx = p₀x + p₁x²/2 + p₂x³/3 + p₃x⁴/4.

$$\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]$$
$$h = \frac{b-a}{n}$$

How to Use

  1. Enter lower bound a and upper bound b (b>a).
  2. Enter subintervals n (larger = more accurate).
  3. Enter polynomial coefficients p₀–p₃ (default f(x)=x²).
  4. The tool gives the trapezoidal estimate, exact integral and error, with per-trapezoid areas in the note.

Trapezoidal error for ∫₀² x² dx at various n

Trapezoidal error for ∫₀² x² dx at various n
nEstimateExactError
22.5000002.6666670.166667
42.7500002.6666670.083333
82.6875002.6666670.020833
162.6718752.6666670.005208

Error falls roughly as 1/n²; convex functions are overestimated.

Case Studies

∫₀² x² dx, n=4

Exact = [x³/3]₀² = 8/3 ≈ 2.666667.

h=0.5; points 0,0.5,1,1.5,2; f=0,0.25,1,2.25,4.

Estimate=(0.5/2)[0+2(0.25+1+2.25)+4]=2.75; error=0.083333.

∫₀¹ 1 dx (constant), n=2

Exact = 1.

Trapezoidal rule is exact for any n (no error for constants).

∫₀¹ x dx, n=2

Exact = ½.

h=0.5, points 0,0.5,1; f=0,0.5,1. Estimate=0.25(0+1+1)=0.5; error 0.

∫₀³ x³ dx, n=3

Exact = 81/4 = 20.25.

Trapezoidal has error for cubics; increasing n helps.

Doubling n

∫₀² x² dx: n=4 error 0.0833; n=8 error ≈0.0208 (about ¼).

Trapezoidal error scales roughly as 1/n².

∫₋₁¹ x² dx, n=4

Exact = 2/3 ≈ 0.666667.

On a symmetric interval, a convex even function is still slightly overestimated.

FAQ

Why does the trapezoidal rule have error?

It approximates the curve with straight segments; when the function curves (non-zero second derivative) an error appears. Convex functions are overestimated, concave underestimated.

Is larger n always better?

Generally larger n reduces error (≈1/n²), but too large may accumulate floating-point error; this tool gives the exact value for comparison.

Why zero error for constants and lines?

The trapezoidal rule connects points with lines, exactly matching constant and linear functions, so the estimate equals the exact value.

Polynomials only?

This tool restricts f(x)=p₀+p₁x+p₂x²+p₃x³ to provide an exact reference. Other functions (sin, e^x) can be estimated by the same formula but without the exact value here.

Trapezoidal vs Simpson's rule?

Simpson's uses parabolic segments and converges faster (error ∝1/n⁴); trapezoidal is simpler but slower — good for teaching.

Can b < a?

This tool assumes b>a; if b<a the sign flips. Ensure the upper bound exceeds the lower.

How is one trapezoid area computed?

The i-th trapezoid area = h·(f(xᵢ)+f(xᵢ₊₁))/2; their sum is the total estimate.

What does the error column mean?

Error = trapezoidal estimate − exact polynomial integral; positive means overestimate, useful to judge if n is enough.

Related Tools

References

Content review: Calculatorism Science Team. Trapezoidal formula, exact polynomial integral and error verified. Results are for reference only.

Found a problem with the results?

If this calculator's result is wrong, or you have any question about the calculation logic, please let us know. You are viewing:Trapezoidal Rule — Numerical Integration/math/trapezoidal-rule)。