Upload
dong
View
85
Download
2
Embed Size (px)
DESCRIPTION
f(x). x. a. b. Numerical Integration General considerations Trapezoid rule Simpson’s rule Error estimates Gaussian quadrature Consider the integral The general strategy for estimating I is to evaluate f(x) at a number of points and approximate I by a sum - PowerPoint PPT Presentation
Citation preview
1
Numerical Integration
1. General considerations
2. Trapezoid rule
3. Simpson’s rule
4. Error estimates
5. Gaussian quadrature
Consider the integral
The general strategy for estimating I is to
evaluate f(x) at a number of points and
approximate I by a sum
where the wi are weight factors.
b
a
dxxfI )(
b
a
N
iii
iiNN
wfdxxfI
xffbxxxxa
1
121
)(
)(
a b x
f(x)
Criteria for the choice of a method are the desired accuracy, the efficiency of the method and particular properties of the integrand (for example singularities).
2
Trapezoid rule
• N evenly spaced points xi
• n=N-1 intervals of size h
• in each interval, approximate the curve f(x) by a straight line (Taylor expansion to first order) a=x1 b=x5
x
f(x)
x2 x3 x4
h
T1 T2 T3 T4
N=5, n=4
N
N
iiiT
N
iiNN
N
N
N
NNNNnT
iiiiiii
i
ffffh
hhhh
wfwfwI
fhffh
f
w
hf
whf
whf
w
h
ffh
ffh
ffh
ffh
TTTII
ffh
ffxxT
NihiaxN
abh
,,, and2
,,,,,2
with
)(222
)(2
)(2
)(2
)(2
trapezoid theof area)(2
)(2
1)(
,,1,)1(1
211
1
211
1
2
2
1
1
112322121
111
3
Simpson’s rule
• N evenly spaced points xi
• n=N-1 intervals of size h
• in each pair of intervals, approximate the curve f(x) by a parabola (Taylor expansion to second order)
h
a=x1 b=x5x
f(x)
x2 x3 x4
N=5
)2(1
)])()([)]()(([1
))2
()2
((1
)(but
)(3
1)(2
3
1)(
2
1
2
1)()()(
2
1)()()(
112
2
3
321
1
2
iii
iiiiiii
ii
h
hi
h
hi
h
hi
i
i
h
h
iii
fffh
hxfxfxfhxfh
hxf
hxf
hxf
xfhxhf
yxfyxfyxfx
xyxfyxfxfdydxxf
hyhxxx
y
xxxfyxxxfxfxf iiiiiii
11
2
2 for)()(2
1)()()()(
4
N
N
iiiS
NNNS
b
a
iiiiii
x
x
i
ffffhhhhhhh
wfwfwI
hfhfhfhfhf
hf
hfhfhfhfIdxxfI
ban
hfhfhffffh
hhfdxxfi
i
,,, and3
,3
4,,
3
2,
3
4,
3
2,
3
4,
3with
3
1
3
4
3
1
3
1
3
4
32
3
1
3
1
3
4
3
1)(
to from integral for the valueobtain the tointervals of pairs 2
theof onscontributi theadd
3
1
3
4
3
1)2(
1
3
12)(
211
1254
3
3321
1112
31
1
• The Simpson rule approximation IS to the integral I is called Sn in Cooper, A Matlab Companion … , pp 172-173
• The number of intervals (n = N-1) has to be even!
• The sum over the weights provides a useful check of the derivation
N
ii abnhhNw
1
)()1(
5
Error estimates
5)4(
5
4)4(34)4(3
11
2
4)4(32
)(60
1
52
)(!4
1
0
)(!3
1)(
!4
1)(
!3
1
:intervals ofpair single aover integral in the error the
estimatingby start We.sorder termfourth and third the todue valueintegral in the
error theestimate now usLet .order toup termsconsidered have werule, sSimpson'For
)(!4
1)(
!3
1)(
2
1)()()(
writebefore, as ; about )( ofexpansion Taylor heConsider t
hxf
h
dyyxfdyyxfyxfyxfdy
hyhxxx
IE
y
yxfyxfyxfyxfxfxf
xxyxxf
i
h
h
i
h
h
iii
h
h
S
iiS
SS
iiiii
ii
Note: the value of the prefactor for S is incorrect because we have also approximated the second derivative of f (x) when we derived Simpson’s rule. A more careful analysis yields:
ban
abfhabfE
nEhf
n
ab
n
abh
xxhf
S
SSS
iiS
such that somefor )(
)(180
1))((
180
1
2for and)(
)(
90
1 find we
)( Using
such that somefor )(90
1
4
5)4(4)4(
4)4(
115)4(
6
• Even though we have used second order polynomials to approximate the function over the pairs of intervals, the Simpson rule yields exact results for polynomials up to third order, since the error is proportional to a fourth-order derivative.
• ES 1/n4 doubling the number of intervals reduces the error by a factor 16 .
• The error estimates for the Trapezoid rule are derived in a similar way and given by
4factor aby error thereduces intervals ofnumber thedoubling
such that somefor )(
)(12
1)()(
12
1
such that somefor )(12
2
32
1
3
ban
abfhfabE
xxfh
T
iiT
Matlab offers a numerical integration routine quad that uses an adaptive Simpson quadrature. Quadruature is the general term for numerical integration methods (from counting squares under a curve). An adaptive integration method uses different interval sizes depending on the behavior of the function and the desired tolerance.
Assume we want to evaluate the integral between two points u and v with au<vb: 1. Split [u,v] into two intervals of size h and use Simpson’s rule, call the result S(2) 2. Split [u,v] into four intervals of size h/2 and use Simpson’s rule, call the result S(4) 3. Calculate the error estimate (2) | S(4)- S(2)|4. If the error is smaller than the tolerance, accept the result and go on to the next interval [v,w]. Otherwise, split [u,v] into 8 intervals of size h/4 , etc.
7
Gaussian quadrature
Please read the handouts from: A. L. Garcia, Numerical Methods for Physics, pp 325-328, and Landau and Paez, Computational Physics, pp 55-57
Remember the general form of numerical integration:
)(andwith)( 1211
iiNN
b
a
N
iii xffbxxxxawfdxxfI
Gaussian quadratures use evaluation points xi (not evenly spaced) and weights wi that yield an optimum approximation to the integral for specific types of functions.
Gaussian quadrature is the preferred method if you can choose a type (Legendre, Laguerre, Chebyshev, etc. ) appropriate for your problem. In that case, you can achieve much higher accuracy with many fewer evaluation points compared to the other integration methods.
However, in general, it is difficult to estimate the error and there is no guarantee that the result is a good approximation to the integral.
Matlab offers a routine quadl that employs a variant of Gaussian quadrature. It may work very well, but be careful when using it and check your results with a different method from time to time.