Trapezoidal rule

From Wikipedia, the free encyclopedia
Revision as of 09:35, 22 May 2025 by imported>D.Lazard (Uniform grid: more indentation fo clarifying that the left member of the equality is not the integral)
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Template:Short description Script error: No such module "about".

File:Trapezoidal rule illustration.svg
The function f(x) (in blue) is approximated by a linear function (in red).

In calculus, the trapezoidal rule (or trapezium rule in British English)Template:Efn is a technique for numerical integration, i.e., approximating the definite integral: abf(x)dx.

The trapezoidal rule works by approximating the region under the graph of the function f(x) as a trapezoid and calculating its area. It follows that abf(x)dx(ba)12(f(a)+f(b)).

File:WikiTrap.gif
An animation that shows what the trapezoidal rule is and how the error in approximation decreases as the step size decreases

The integral can be even better approximated by partitioning the integration interval, applying the trapezoidal rule to each subinterval, and summing the results. In practice, this "chained" (or "composite") trapezoidal rule is usually what is meant by "integrating with the trapezoidal rule". Let {xk} be a partition of [a,b] such that a=x0<x1<<xN1<xN=b and Δxk be the length of the k-th subinterval (that is, Δxk=xkxk1), then abf(x)dxk=1Nf(xk1)+f(xk)2Δxk. The trapezoidal rule may be viewed as the result obtained by averaging the left and right Riemann sums, and is sometimes defined this way.

The approximation becomes more accurate as the resolution of the partition increases (that is, for larger N, all Δxk decrease).

When the partition has a regular spacing, as is often the case, that is, when all the Δxk have the same value Δx, the formula can be simplified for calculation efficiency by factoring Δx out:. abf(x)dxΔx(f(x0)+f(xN)2+k=1n1f(xk)).

As discussed below, it is also possible to place error bounds on the accuracy of the value of a definite integral estimated using a trapezoidal rule.

File:Integration num trapezes notation.svg
Illustration of "chained trapezoidal rule" used on an irregularly-spaced partition of [a,b].

History

A 2016 Science paper reports that the trapezoid rule was in use in Babylon before 50 BCE for integrating the velocity of Jupiter along the ecliptic.[1][2]

Numerical implementation

Non-uniform grid

When the grid spacing is non-uniform, one can use the formula abf(x)dxk=1Nf(xk1)+f(xk)2Δxk, wherein Δxk=xkxk1.

Uniform grid

For a domain partitioned by N equally spaced points, considerable simplification may occur.

Let Δx=baN, and xk=a+kΔx for Template:Tmath. The approximation to the integral becomes abf(x)dxΔx2k=1N(f(xk1)+f(xk))=Δx(f(xN)+f(x0)2+k=1N1f(xk)).

Error analysis

File:Trapezium2.gif
An animation showing how the trapezoidal rule approximation improves with more strips for an interval with a=2 and b=8. As the number of intervals N increases, so too does the accuracy of the result.

The error of the composite trapezoidal rule is the difference between the value of the integral and the numerical result: E=abf(x)dxbaN[f(a)+f(b)2+k=1N1f(a+kbaN)]

There exists a number ξ between a and b, such that[3] E=(ba)312N2f(ξ)

It follows that if the integrand is concave up (and thus has a positive second derivative), then the error is negative and the trapezoidal rule overestimates the true value. This can also be seen from the geometric picture: the trapezoids include all of the area under the curve and extend over it. Similarly, a concave-down function yields an underestimate because area is unaccounted for under the curve, but none is counted above. If the interval of the integral being approximated includes an inflection point, the sign of the error is harder to identify.

An asymptotic error estimate for N → ∞ is given by E=(ba)212N2[f(b)f(a)]+O(N3). Further terms in this error estimate are given by the Euler–Maclaurin summation formula.

Several techniques can be used to analyze the error, including:[4]

  1. Fourier series
  2. Residue calculus
  3. Euler–Maclaurin summation formula[5][6]
  4. Polynomial interpolation[7]

It is argued that the speed of convergence of the trapezoidal rule reflects and can be used as a definition of classes of smoothness of the functions.[8]

Proof

First suppose that h=baN and ak=a+(k1)h. Let gk(t)=12t[f(ak)+f(ak+t)]akak+tf(x)dx be the function such that |gk(h)| is the error of the trapezoidal rule on one of the intervals, [ak,ak+h]. Then dgkdt=12[f(ak)+f(ak+t)]+12tf(ak+t)f(ak+t), and d2gkdt2=12tf(ak+t).

Now suppose that |f(x)||f(ξ)|, which holds if f is sufficiently smooth. It then follows that |f(ak+t)|f(ξ) which is equivalent to f(ξ)f(ak+t)f(ξ), or f(ξ)t2gk(t)f(ξ)t2.

Since gk(0)=0 and gk(0)=0, 0tgk(x)dx=gk(t) and 0tgk(x)dx=gk(t).

Using these results, we find f(ξ)t24gk(t)f(ξ)t24 and f(ξ)t312gk(t)f(ξ)t312

Letting t=h we find f(ξ)h312gk(h)f(ξ)h312.

Summing all of the local error terms we find k=1Ngk(h)=baN[f(a)+f(b)2+k=1N1f(a+kbaN)]abf(x)dx.

But we also have k=1Nf(ξ)h312k=1Ngk(h)k=1Nf(ξ)h312 and k=1Nf(ξ)h312=f(ξ)h3N12,

so that

f(ξ)h3N12baN[f(a)+f(b)2+k=1N1f(a+kbaN)]abf(x)dxf(ξ)h3N12.

Therefore the total error is bounded by

error=abf(x)dxbaN[f(a)+f(b)2+k=1N1f(a+kbaN)]=f(ξ)h3N12=f(ξ)(ba)312N2.

Periodic and peak functions

The trapezoidal rule converges rapidly for periodic functions. This is an easy consequence of the Euler-Maclaurin summation formula, which says that if f is p times continuously differentiable with period T k=0N1f(kh)h=0Tf(x)dx+k=1p/2B2k(2k)!(f(2k1)(T)f(2k1)(0))(1)php0TB~p(x/T)f(p)(x)dx where h:=T/N and B~p is the periodic extension of the pth Bernoulli polynomial.[9] Due to the periodicity, the derivatives at the endpoint cancel and we see that the error is O(hp).

A similar effect is available for peak-like functions, such as Gaussian, Exponentially modified Gaussian and other functions with derivatives at integration limits that can be neglected.[10] The evaluation of the full integral of a Gaussian function by trapezoidal rule with 1% accuracy can be made using just 4 points.[11] Simpson's rule requires 1.8 times more points to achieve the same accuracy.[11][12]

"Rough" functions

For functions that are not in C2, the error bound given above is not applicable. Still, error bounds for such rough functions can be derived, which typically show a slower convergence with the number of function evaluations N than the O(N2) behaviour given above. Interestingly, in this case the trapezoidal rule often has sharper bounds than Simpson's rule for the same number of function evaluations.[13]

Applicability and alternatives

The trapezoidal rule is one of a family of formulas for numerical integration called Newton–Cotes formulas, of which the midpoint rule is similar to the trapezoid rule. Simpson's rule is another member of the same family, and in general has faster convergence than the trapezoidal rule for functions which are twice continuously differentiable, though not in all specific cases. However, for various classes of rougher functions (ones with weaker smoothness conditions), the trapezoidal rule has faster convergence in general than Simpson's rule.[13]

Moreover, the trapezoidal rule tends to become extremely accurate when periodic functions are integrated over their periods, which can be analyzed in various ways.[8][12] A similar effect is available for peak functions.[11][12]

For non-periodic functions, however, methods with unequally spaced points such as Gaussian quadrature and Clenshaw–Curtis quadrature are generally far more accurate; Clenshaw–Curtis quadrature can be viewed as a change of variables to express arbitrary integrals in terms of periodic integrals, at which point the trapezoidal rule can be applied accurately.

Example

The following integral is given: 0.11.35xe2xdx Template:Ordered list Solution Template:Ordered list

See also

Notes

Template:Notelist

  1. Script error: No such module "Citation/CS1".
  2. Script error: No such module "citation/CS1".
  3. Template:Harvtxt
  4. Script error: No such module "Footnotes".
  5. Template:Harvtxt
  6. Template:Harvtxt
  7. Template:Harvtxt
  8. a b Script error: No such module "Footnotes".
  9. Script error: No such module "citation/CS1".
  10. Script error: No such module "Citation/CS1".
  11. a b c Script error: No such module "Citation/CS1".
  12. a b c Script error: No such module "Footnotes".
  13. a b Script error: No such module "Footnotes".

References

Template:Refbegin

  • Script error: No such module "citation/CS1".
  • Script error: No such module "citation/CS1".
  • Script error: No such module "citation/CS1".
  • Script error: No such module "citation/CS1".
  • Script error: No such module "citation/CS1".

Template:Refend

External links

Template:Sister project

Template:Numerical integration Template:Calculus topics