‘Trapezoidal rule - Wikipedia, the free encyclopedia Page 1 of
Trapezoidal rule
From Wikipedia, the fee excyclopedia
In mathematics, the trapezoidal rule (also known asthe trapezoid
rule, or the trapezium rule in British English) is a way to
approximately calculate tie definite integral
J Heae.
‘ets reworks by approxima hereon ender te———hacntcys
raph ofthe function f(x} asa trapezoid and calculating its area. It ‘pproximatel by a ine
Peres aes
Hla 50),
[fejdex 0g LOLLO,
To caleulate this integral more accurately, one firs pis the interval of
integration [4,5] into m smaller subintervals, and then applies the
trapezoidal rule on each of ther One obiains the compasite
trapezoidal ride:
‘Mastration ofthe composite
trapezoidal rte (with po
uniform gid)
A
“a
Mhstation ofthe composite
trapezoidal ule (with 3
‘niforn gr),
° wba [flay +f)
[foyer = $ +E s (ass
‘This can alternatively be written as:
[Heyer = "S9 (Hoe) + 2fler) + 2flen) +> + 2f tna) + Sta)
‘nup/ien.wikipedia org/wiki/Trapecoidal_nule 12/11/2009‘Trapezoidal rule - Wikipedia, the free encyclopedia Page 20f4
b
a, =a+k for k=0,1,....0
(one can also use a non-uniform grid),
‘The trapezoidal rule is one ofa family of formulas for numerical integration called Newton-Cotes
formulas. Simpson's rule s another, often more aecurate, member ofthe same family. Simpson's rule
and other like methods can be expected to improve onthe trapezoidal rule for functions which are twice
continuously differentiable; however for rougher functions the trapezoidal rule is ikely to prove
preferable. Moreover, the trapezoidal rule tends to become extremely accurate when periodic Functions
are integrated over ther periods, a fact best understood in connection with the Euler-Maclaurin
‘summation formula. For non-petiodie 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 te trapezoidal rule can be applied accurately
[Contents
= 1 Error analysis
= 2 Python implementation
= 3 MATLAB implementation,
= 4 See also |
= 5 Notes,
= 6 References
#7 Extemal links |
Error analysis
‘The error ofthe composite trapezoidal rule isthe difference between the value of the integral and the
numerical result:
me [58.3
This error can be writen at
(b= a) oy
el".
error
where ¢is some number between a and bl!
{It follows that ifthe integrin is concave up (and thus has a positive second derivative), then the eror is
negative and the trapezoidal rule overestimates the true value. This ean also be seen from the geometric
picture: the trapezoids include all ofthe area under the curve and extend over it. Similarly a cancave-
down function yields an underestimate because area is unaccounted for under the curve, but none is
‘counted above If the interval ofthe integral being approximated includes an inflection point, then the
‘error is harder to identity.
nupi//en wikipedia org/wiki/Trapezoidal_rule 12/11/2009‘Trapezoidal rule - Wikipedia, the ee encyclopedia Page 3 oF
An asymptotic eror estimate for n —+ is given by
(b=ay?
Tan?
Further terms inthis error estimate are given by the Buler-Maclaurin summation formula
error
(F®) - F(@) + O(n).
Python implementation
‘The (composite) trapezoidal rule can be implemented in Python as follows:
| #l/use/bin/env python
def trapezoidal_rule(f, a, b, N):
"Approximate the definite integral of f from a to b by the
| composite trapezoidal rule, using N subintervals"™"
return (b-a! * ( f(a)/2 + £(b)/2 + sum((f(a + (b-a)*k/N) for
Peest
MATLAB implementation
‘The (composite) trapezoiéal rule ean be implemented in MATLAB as follows
function [F] = trap(f,a,byn)
Sfename of function, anstart value, beend value, nenumber of
iterations !
tmade by Carolina, Niklas, Benjamin and Damiano
he (bea) ./n7
Sef (als
deL:lin-L
wrath. tir
yet (x)
52542. *sum(y):
| SeSHE Gb):
Foh.*S.
Le
| ena
See also
Rectangle method
hnpzten.wikipedia.org/wikiTrapecoidal_rule 12/11/2009‘Trapezoidal rule - Wikipedia, the free encyclopedia Page 404
= Simpson's rule
= Romberg integration
# Newton-Cotes formulas
Notes
L._* Atkinson (1989), equation (5.1.7)
2. * Atkinson (1989), equation (5.1.9)
References
‘= Atkinson, Kendall A. (1989), Aw Introduction to Numerical Analysis (2nd e4.), New York: John
Wiley & Sons, ISBN 978-0-471-50023-0.
+ Burden, Richard L., J. Douglas Faires (2000), Numerical Analysis (th Ed. ed), Brooks/Cole,
ISBN 0-534-38216.9,
External links
+= Trapezoidal Rule fer Numerical Integration
1 Notes on the convergence of trapezoidal-rule quadrature
= Trapezoidal Rule of Integration - Notes, PPT, Videos, Mathcad, Matlab, Mathematica, Maple,
Multiple Choice Tests at Holistic Numerical Methods Institute
Retrieved from "htp/en.wikipedia org/wiki/Traperoid
Categories: Numerical infogration (quadrature)
‘= This page was last modified on 4 December 2009 at 21:42,
‘= Textis available under the Creative Commons Attribution-ShareA ike License; additional terms
may apply. See Terms of Use for detail.
Wikipedia® is a registered trademark ofthe Wikimedia Foundation, Ine. a non-profit
organization.
= Contact us
‘ntip://en.wikipedia org/wiki/Trapezoidal_rule 121172009