Calculator · Engineering Mathematics

Trapezoidal Rule Calculator

Approximate a definite integral by replacing f with a straight line on each of n equal subintervals. Second-order accurate for smooth integrands and the natural first rule to reach for.

Problem definition

Operators + − * / ^, parentheses, pi and e, and sin, cos, tan, asin, acos, atan, exp, sqrt, abs, ln, log, log10. Write 2*x, not 2x.

n is a whole number between 1 and 10,000, the documented browser-safety cap. A fractional n is rejected, never rounded. The run costs n + 1 evaluations of f.

Results

Integral estimate Q1.974231602
Interval [a, b][0, 3.142]
Subintervals n8
Step h = (b − a)/n0.3927
Function evaluations9

Integrand and partition

f(x)interval bounds a, btrapezoid chordsquadrature nodes
f(x) = sin(x) on [0, 3.142]. The dashed path joins the node values and is exactly what the trapezoidal rule integrates; it is drawn only for a modest n.

Nodes and weights

Trapezoidal nodes
ixᵢf(xᵢ)cᵢweight wᵢwᵢ·f(xᵢ)
0000.50.19630
10.39270.382710.39270.1503
20.78540.707110.39270.2777
31.1780.923910.39270.3628
41.571110.39270.3927
51.9630.923910.39270.3628
62.3560.707110.39270.2777
72.7490.382710.39270.1503
83.1421.225e-160.50.19632.405e-17

Continue

Open in Numerical Integration Lab

f(x), the interval and n continue into the Lab with the trapezoidal sweep enabled. No reference integral is carried over, because this calculator does not have one.

Assumptions & validity

  • · f is finite at every node; a non-finite value is a reported failure, not a skipped point.
  • · The O(h²) statement assumes f has a continuous second derivative on the whole interval.
  • · A discontinuity, a kink or an unbounded derivative anywhere in [a, b] invalidates that rate, and refinement then improves the estimate more slowly than expected.
  • · a > b is integrated in the orientation given and returns the correct negative value; the bounds are never silently reordered.
  • · a = b returns exactly zero without evaluating f at all.
  • · This is a proper integral over a finite interval: infinite bounds and unbounded integrands are out of scope.

Technical reference

h = (b − a) / n

xᵢ = a + i·h, i = 0 … n

Tₙ = h [ ½f(x₀) + Σᵢ₌₁ⁿ⁻¹ f(xᵢ) + ½f(xₙ) ]

Error for f ∈ C²: Tₙ − I = +(b − a) h² f″(ξ) / 12 for some ξ in (a, b), equivalently I − Tₙ = −(b − a) h² f″(ξ) / 12

I
the exact definite integral
Tₙ
composite trapezoidal estimate with n subintervals
h
step size, signed with the orientation of the interval
n
number of subintervals
f″
second derivative of the integrand

The rule is exact for constant and linear integrands: a straight line through the two endpoints of a subinterval IS the integrand there.

Global error is O(h²) for a twice continuously differentiable f, so halving h quarters the error. That behaviour is a property of the smoothness of f, not of the formula alone.

The sign convention here is ESTIMATE MINUS EXACT, matching the order in which the results above are presented: a positive f″ on the interval makes the trapezoidal estimate overshoot the exact integral, which is exactly what chords above a convex curve do.

The error term is proportional to f″, so the rule is at its worst where the integrand is strongly curved, and at its best on nearly straight stretches.

Interior nodes carry coefficient 1 and the two endpoints carry ½; that is the only difference from a plain Riemann sum on the same nodes.

The signed step carries orientation, so reversing the bounds negates the result exactly, as the mathematics requires.

The cap on n is a browser-safety limit, not a mathematical one; it is enforced identically here and in the Lab.

Related tools