5. Integration
2. Quadrature as Box Counting
3. Algorithm: Trapezoid Rule
4. Algorithm: Simpson’s Rule
5. Integration Error
6. Algorithm: Gaussian Quadrature
7. Empirical Error Estimate
8. Experimentation
9. Higher Order Rules
5.2. Quadrature as Box Counting
Riemann: /
01
limb b a h
ih
ia
f x d x h f x
Numerical:
1
b N
i iia
f x d x w f x
w = weight
• Keeping N finite can still give exact results, e.g., polynomials.
• Aim: accurate result for small N.
• No universal “best” algorithm.
Tips
• Remove singularities first.
• By putting them at endpoints of sub-intervals
• By change of variable.
1 0 1
1 1 0
x f x d x x f x d x x f x d x
1 11/3 3
0 0
3x d x y d y 1/3y x
21 1
2 20 0
12
1 2
f yf xd x d y
x y
2 1y x
• Speed up or slow down (by change of variable or step size)
in slowly or rapidly varying region.
Algorithms for Evenly Spaced Points
Evenly spaced points :
1
b N
i iia
f x d x w f
1ix a i h b a
hN
1, ,i N
Name Degree wi
Trapezoid 1
Simpson’s 2
3/8 3
Milne 4
11 ,1
2h
11 , 4 ,1
3h
31 , 3 , 3 ,1
8h
114 , 64 , 24 , 64 ,14
45h
i if f x
8.3. Algorithm: Trapezoid Rule
1
1
1
2
i
i
x
i i
x
f x d x h f f
0 1 1 2 2 1 1
1
2
b
N N N N
a
f x d x h f f f f f f f f
0 1 2 2 1
1 1
2 2N N Nh f f f f f f
1
b N
i iia
f x d x w f x
1 1,1 , ,1 ,
2 2iw h
1 0 0
0
1
2
h
f x d x f f h f h
f x ax b
0 1
1
2h f f
0f b
1f a h b
1 0
0
f fa
hb f
1 0
0
f ff x x f
h
5.4. Algorithm: Simpson’s Rule
2f x ax bx c
21
0
21
f ah bh c
f c
f ah bh c
21 1 0
1 1
0
1
21
2
ah f f f
bh f f
c f
322
3
h
h
f x d x a h c h
1 1 0 0
1 22
3 3h f f f f
1 0 1
14
3h f f f
2
1 2
14
3
i
i
x
i i i
x
f x d x h f f f
1
b N
i iia
f x d x w f x
11 , 4 , 2 , 4 , 2 , , 4 , 2 , 4 ,1
3iw h
N = odd int
11
2N N
int1
11 4 1
3
N
ii
w h N
1N h
0 1 2 2 3 4 4 3 2 2 1
14 4 4 4
3
b
N N N N N N
a
f x d x h f f f f f f f f f f f f
0 1 2 3 4 3 2 14 2 4 2 4 2 43 N N N N
hf f f f f f f f f
2
1 2
14
3
i
i
x
i i i
x
f x d x h f f f
b a
5.5. Integration Error
42 3 40 0 0 0 0
1 1 1
2 3! 4!f x f f x f x f x f x
Expand f at middle of interval x [ h, h ] :
43 50 0 0
2 22
2 3 4! 5
h
h
f x d x f h f h f h
Error, Trapezoid :
int
1
2
b ah
N
3int 0tE O N f h
3
02int
1O f b a
N
Error,Simpson :
4 5int 0sE O N f h
5404
int
1O f b a
N
n data points in each interval
n = 2
n = 4
Relative error :,
,t s
t s
E
f
1
nn
n
fb a
N f
1
,
nn
t s n
fb a
N f n = 2,4 for t , s
Round-off error is random : ro mN m machine precision ~ 107 ( single prec) ~ 1015 ( double prec)
,tot t s ro ,
1 10
2tot
t s m
dn
d N N
Min tot : ,t s m
Set scale to
1nf
f 1b a
Trapezoid :
1
nn
mn
fb a N
N f
2
2 11
n nn
m
fN b a
f
2/51510N
2
2 1nmN
tot mN 1
12 1n
m
610 4/515 1210 10tot
Simpson :
2/91510N 10/310 2154 8/915 40/3 1410 10 4.6 10tot
Conclusions
• Simpson’s rule is better than trapezoid.
• It’s possible to get tot m .
• Best result is obtained for N ~ 1000 instead of .
5.6. Algorithm: Gaussian Quadrature
( ) ( )b
a
I d x f x w x1
( )n
k kk
S A f x
( )
( ) '( )
b
kk ka
xA dx
x x x
where is the nth degree member of a complete set of orthogonal polynomials, and { xk } are its roots.
I = S if f is an 2n-1 degree polynomial. Proof :
Integral Polynomial weight Limits
Legendre 1 ( 1, 1 )
Hermite exp( x2 ) ( , )
Laguerre exp( x ) ( , )
Chebyshev I ( 1x2 )1/2 ( 1, 1 )
1
1
( )d x f x
2
( )xd x e f x
( )xd x e f x
1
21
1( )
1d x f x
x
5.6.1. Mapping Integration Points
An integral b
a
F y d y can be transformed into 1
1
f x d x
y x by the linear transform
a
b
Thus
1
21
2
b a
b a
1
2
1
2 y b a x b a
f x b a F y
1
2d y b a d x
1
2y b a x b a
An integral 0
F y d y
can be transformed into 1
1
f x d x
1y
x
by the linear transform
02
0
Thus 2
21
2 1
1 xy
x
f x F yx
21
d y d xx
1 1
1 2y
x
1
2 1
x
x
0
Similarly, one get the following transforms
Interval W y
[ a , b ]
[ 0 , ]
[ , ]
[ b , ]
[ 0 , b ]
1
interval 1
F y d y f x d x
1
2W b a
21
Wx
1
2b a x b a
1
2 1
x
x
0
2
22
2 1
1
xW
x
2
2
1
x
x
21
Wx
2
2
1
2
bW
x
1
2 1
xb
x
1 11
2
xb
x
f x W F y x
5.7. Empirical Error Estimate (Ex.5.1)
Relative error, , as a function of N
for the trapezoid, Simpson, & Gaussian methods, in the calculation of
Answer
11
0
1tI e d t e
numerical exact
exact
5.8. Experimentation
Evaluate
2
0
sin 1000 x d x
and 2
0
sin 100x
x d x
What’s wrong ?
5.9. Higher Order Rules
2 4b
a
A h f x d x h h
Let A(h) be the numerical evaluation of an integral with leading error h2, i.e.,
2 41 1
2 4 16
b
a
hA f x d x h h
44 1 1
3 2 3 4
b
a
hA A h f x d x h Romberg’s
extrapolation
see Burden, § 4.5
Top Related