acalculator

What does the trapezoidal rule give?

Type a function, the limits a and b, and the number of subintervals. The trapezoidal rule calculator shows the trapezoidal approximation of the integral, every point it uses, and the midpoint and Simpson's rule values.

Your numbers

Trapezoidal rule Tₙ
0.34375

The trapezoidal rule with n = 4 gives 0.34375 for the integral of x^2 from 0 to 1.

Δx
0.25
Midpoint rule Mₙ
0.328125
Simpson’s rule Sₙ
0.3333333333
Weighted sum
2.75
Years
5

Trapezoidal rule Tₙ: 0.34375. The trapezoidal rule with n = 4 gives 0.34375 for the integral of x^2 from 0 to 1.

The trapezoid tops: f at each point

Every point

How to calculate

Approximates the definite integral of f(x) from a to b with the trapezoidal rule in n subintervals, with every point, the midpoint rule and Simpson’s rule for comparison.

Example with the default inputs (f(x) x^2, Lower limit (a) 0, Upper limit (b) 1, Subintervals (n) 4): The trapezoidal rule with n = 4 gives 0.34375 for the integral of x^2 from 0 to 1.

Method: Δx = (b − a) ÷ n; xᵢ = a + iΔx; Tₙ = Δx/2 × (f(x₀) + 2f(x₁) + … + 2f(xₙ₋₁) + f(xₙ)); Mₙ = Δx × Σ f(a + (i − ½)Δx); Sₙ = Δx/3 × (f(x₀) + 4f(x₁) + 2f(x₂) + … + 4f(xₙ₋₁) + f(xₙ)).

  • f must have a real value at every point used (and at every midpoint).
  • xᵢ comes exactly from the typed decimals; f and the sums are in double precision.
  • 1 to 1,000 subintervals; a and b from −10⁹ to 10⁹, and different. Simpson’s rule needs an even n.

Machine-readable copies: Markdown, JSON.

Worked examples

Each example is checked against the calculator on every build.

  1. f(x) x^2, Lower limit (a) 0, Upper limit (b) 1, Subintervals (n) 4 gives Trapezoidal rule Tₙ 0.34375, Midpoint rule Mₙ 0.328125, Δx 0.25, Simpson’s rule Sₙ 0.333333.Source: OpenStax, Calculus Volume 2, §3.6 Numerical Integration (midpoint rule, trapezoidal rule, Simpson’s rule; Examples 3.39, 3.41 and 3.45). https://openstax.org/books/calculus-volume-2/pages/3-6-numerical-integration (T₄ = 11/32, M₄ = 21/64)
  2. f(x) x^3, Lower limit (a) 0, Upper limit (b) 1, Subintervals (n) 2 gives Simpson’s rule Sₙ 0.25, Trapezoidal rule Tₙ 0.3125.Source: OpenStax, Calculus Volume 2, §3.6 Numerical Integration (midpoint rule, trapezoidal rule, Simpson’s rule; Examples 3.39, 3.41 and 3.45). https://openstax.org/books/calculus-volume-2/pages/3-6-numerical-integration (S₂ = 1/4)
  3. f(x) sqrt(1 + x^2), Lower limit (a) 1, Upper limit (b) 4, Subintervals (n) 6 gives Midpoint rule Mₙ 8.143073, Simpson’s rule Sₙ 8.145944, Trapezoidal rule Tₙ 8.151209.Source: OpenStax, Calculus Volume 2, §3.6 Numerical Integration (midpoint rule, trapezoidal rule, Simpson’s rule; Examples 3.39, 3.41 and 3.45). https://openstax.org/books/calculus-volume-2/pages/3-6-numerical-integration (M₆ ≈ 8.1431, S₆ ≈ 8.14594)

How it works

  • Δx = (b − a) ÷ n, and xᵢ = a + i × Δx for i = 0 to n, both exact fractions of the typed decimals, then rounded once to a double. b may be below a (Δx is then negative); a = b has no answer.
  • Trapezoidal rule: Tₙ = Δx/2 × (f(x₀) + 2f(x₁) + 2f(x₂) + … + 2f(xₙ₋₁) + f(xₙ)). The weighted sum in brackets is shown too.
  • Midpoint rule: Mₙ = Δx × (f(m₁) + … + f(mₙ)), with mᵢ = a + (i − ½)Δx (exact, then rounded).
  • Simpson's rule (even n only): Sₙ = Δx/3 × (f(x₀) + 4f(x₁) + 2f(x₂) + 4f(x₃) + … + 2f(xₙ₋₂) + 4f(xₙ₋₁) + f(xₙ)).
  • f is evaluated in double precision and summed in order from x₀. If f has no real value at a point (such as √x for x < 0), there is no answer, and the message names the point.
  • The page shows numbers up to 10³⁰⁰ in size. A value of f past 10³⁰⁰ (such as eˣ at x = 691) is too large to show, and the message names the point. A result past 10³⁰⁰ (Tₙ, Mₙ, Sₙ or the weighted sum) is also too large to show. In both cases there is no answer.
  • Typing: x² as x^2, √ as sqrt( ), eˣ as exp(x), and sin, cos, tan (in radians), ln (the natural log) and abs; multiplication may be written 2x or 2*x.

Output format. Every number shows to 10 significant figures, rounded half up. The chart joins the points (xᵢ, f(xᵢ)): the tops of the trapezoids.

Assumptions

  • 1 to 1,000 subintervals; a and b from −10⁹ to 10⁹.
  • The rules estimate the integral; they do not find it exactly, except for functions they fit exactly (straight lines for Tₙ and Mₙ, cubics for Sₙ).

Worked examples by hand

∫₀¹ x² dx, n = 4 (OpenStax Examples 3.39 and 3.41). Δx = 0.25; f = 0, 1/16, 1/4, 9/16, 1. T₄ = 0.125 × (0 + 1/8 + 1/2 + 9/8 + 1) = 0.125 × 11/4 = 11/32 = 0.34375. Midpoints 1/8, 3/8, 5/8, 7/8: M₄ = 0.25 × (1 + 9 + 25 + 49)/64 = 21/64 = 0.328125. S₄ = 0.25/3 × (0 + 4/16 + 2/4 + 36/16 + 1) = 1/3.

∫₀¹ x³ dx, n = 2 (OpenStax Example 3.45). Δx = 0.5; f = 0, 1/8, 1. S₂ = 0.5/3 × (0 + 4/8 + 1) = 1/4. T₂ = 0.25 × (0 + 2/8 + 1) = 0.3125.

∫₁⁴ √(1 + x²) dx, n = 6 (OpenStax Examples 3.40 and 3.46). Δx = 0.5; M₆ = 8.1431, S₆ = 8.14594, T₆ = 8.15121.

Other questions people ask

What is the trapezoidal rule?

It approximates the area under y = f(x) from a to b by n trapezoids of equal width Δx = (b − a) ÷ n: Tₙ = Δx/2 × (f(x₀) + 2f(x₁) + … + 2f(xₙ₋₁) + f(xₙ)). It is the average of the left and right Riemann sums.

How do I use the trapezoidal rule by hand?

For ∫₀¹ x² dx with n = 4: Δx = 0.25, the points are 0, 0.25, 0.5, 0.75, 1 and f is 0, 1/16, 1/4, 9/16, 1. T₄ = 0.125 × (0 + 2/16 + 1/2 + 18/16 + 1) = 11/32 = 0.34375. The exact value is 1/3.

Why do the end points count once and the others twice?

Each inner point is the right side of one trapezoid and the left side of the next, so its height is used twice. The two end points belong to one trapezoid each.

Is the trapezoidal rule an overestimate or an underestimate?

For a function that curves up (concave up) the trapezoids sit above the curve and Tₙ is too large; for one that curves down it is too small. For x² on [0, 1], T₄ = 0.34375 is above the exact 1/3.

How does it compare with the midpoint rule and Simpson’s rule?

The midpoint rule uses the height at the middle of each subinterval; its error bound is half the trapezoidal one. Simpson’s rule fits parabolas and is usually far more accurate: S₄ for x² on [0, 1] is exactly 1/3.

How many subintervals should I use?

More subintervals give a smaller error: the trapezoidal error bound shrinks with 1/n², so doubling n cuts it to a quarter. The calculator allows up to 1,000.