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 Q | 1.974231602 |
|---|---|
| Interval [a, b] | [0, 3.142] |
| Subintervals n | 8 |
| Step h = (b − a)/n | 0.3927 |
| Function evaluations | 9 |
Integrand and partition
Nodes and weights
| i | xᵢ | f(xᵢ) | cᵢ | weight wᵢ | wᵢ·f(xᵢ) |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0.5 | 0.1963 | 0 |
| 1 | 0.3927 | 0.3827 | 1 | 0.3927 | 0.1503 |
| 2 | 0.7854 | 0.7071 | 1 | 0.3927 | 0.2777 |
| 3 | 1.178 | 0.9239 | 1 | 0.3927 | 0.3628 |
| 4 | 1.571 | 1 | 1 | 0.3927 | 0.3927 |
| 5 | 1.963 | 0.9239 | 1 | 0.3927 | 0.3628 |
| 6 | 2.356 | 0.7071 | 1 | 0.3927 | 0.2777 |
| 7 | 2.749 | 0.3827 | 1 | 0.3927 | 0.1503 |
| 8 | 3.142 | 1.225e-16 | 0.5 | 0.1963 | 2.405e-17 |
Continue
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.