VKCMVI
COMPUTATIONAL MATHEMATICS

Trapezoidal rule

Approximate definite integrals with composite trapezoids, grid refinement and Runge error estimates.

Calculator

Load the problem, then select Solve to view the steps. Some advanced examples intentionally fail or do not converge.

Method and applicability

Trapezoidal rule

In=h[f(a)2+∑i=1n−1f(a+ih)+f(b)2]

For sufficiently smooth f, the composite trapezoidal rule has order p = 2.

Use a positive target error to refine the grid automatically, or enter 0 to retain the requested grid.

Results

Worked examples

Basic 1

∫₀¹ x² dx; n = 4

Expected result: I₄ = 0.34375; I = 1/3

Calculation steps
  1. h = 1/4; f(0) = 0; f(1/4) = 1/16; f(1/2) = 1/4; f(3/4) = 9/16; f(1) = 1
  2. I₄ = (1/4)(0 + 1/16 + 1/4 + 9/16 + 1/2) = 11/32
  3. I₈ = 43/128; |I₈ − I₄|/3 = 1/384
  4. |I₄ − 1/3| = 1/96

Source: Original exercise

Academic 2

∫₁² x³ dx; n = 4

Expected result: I₄ = 3.796875; I = 3.75

Calculation steps
  1. h = 1/4
  2. I₄ = ¼[½ + (5/4)³ + (3/2)³ + (7/4)³ + 4]

Source: University of Waterloo · Topic 13.2

Academic 3

∫₁² x³ dx; n = 8

Expected result: I₈ = 3.76171875

Calculation steps
  1. h = 1/8; I₈ = 3.76171875
  2. |I₈ − I₄|/3 = 0.01171875

Source: University of Waterloo · Topic 13.2

Advanced 4

∫₀¹ cos(128πx) dx; n₀ = 4; ε = 10⁻⁶

Expected result: I = 0; |Iₙ| ≤ 10⁻⁶

The initial dyadic grids alias the oscillation; the independent grid should reveal disagreement.

Source: Original exercise

Accuracy and common pitfalls

For f ∈ C²[a,b], the composite rule has an error bound (b−a)h² max|f″|/12. Runge estimates and independent grids do not prove this derivative bound.

Recommended reading