05._Integration

advertisement
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
b

Riemann:
a
 ba  / h

f  x  d x  lim  h  f  xi  
h0
 i 1

b
Numerical:
N
 f  x d x   w f  x 
a
i 1
i
i
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
x
1
1/3
d x   3y3 d y
0
1

0
y  x1/3
0
f  x
1  x2
1
dx 2 
0
f 1  y 2 
2  y2
dy
y2  1  x
• Speed up or slow down (by change of variable or step size)
in slowly or rapidly varying region.
Algorithms for Evenly Spaced Points
b
N
 f  x d x   w
a
i 1
i
fi  f  xi 
fi
xi  a  i  1 h
Evenly spaced points :
i  1,
Name
Degree
wi
Trapezoid
1
1
h 1 , 1
2
Simpson’s
2
1
h 1 , 4 , 1
3
3/8
3
3
h 1 , 3 , 3 , 1
8
Milne
4
h
,N
1
h  14 , 64 , 24 , 64 , 14
45

ba
N
8.3.
f  x   ax  b
h


0
b

a
Algorithm: Trapezoid Rule

f0  b
f1  a h  b
1
f  x  d x  h  f 0  f1    f1  f 2  
2

a
N
f  x  d x   wi f  xi 
i 1
f  x 
xi 1
1
1
f  x  d x   f1  f 0  h  f 0 h  h  f 0  f1 
2
2
1
 h  f 0  f1  f 2 
2
b

f1  f 0
h
b  f0
a


xi
1
f  x  d x  h  f i  f i 1 
2
  f N 2  f N 1    f N 1  f N  
 f N 2  f N 1 
1 
fN 
2 
1
wi  h  , 1 ,
2
1
,1 , 
2
f1  f 0
x  f0
h
Algorithm: Simpson’s Rule
5.4.
f 1  ah  bh  c
f  x   ax 2  bx  c 
f0  c
f1  ah 2  bh  c
h

h

2
1
  1h  f 4f  f 
 h   f 1  f 1   f 0  2 f 0 
1
0
1
3
3
3

2
f  x  d x  a h3  2 c h
3

1
 f 1  f1   f 0
2
1
bh    f 1  f1 
2
c  f0
ah 2 
2
xi  2

xi
1
f  x  d x  h  f i  4 f i 1  f i 2 
3
xi  2

xi
b

a
1
f  x  d x  h  f i  4 f i 1  f i 2 
3
1
f  x  d x  h  f 0  4 f1  f 2    f 2  4 f 3  f 4  
3

b

a
h
 f 0  4 f1  2 f 2  4 f 3  2 f 4
3
N
f  x  d x   wi f  xi 
i 1
N int 

  f N 4  4 f N 3  f N 2    f N 2  4 f N 1  f N  
 4 f N 3  2 f N 2  4 f N 1  f N 
1
wi  h 1 , 4 , 2 , 4 , 2 ,
3
, 4 , 2 , 4 , 1
1
 N  1  N = odd
2
N
1
w

h  N int 1  4  1    N  1 h

i
3
i 1
ba
5.5.
Integration Error
Expand f at middle of interval x  [ h, h ] :
1
1
1 4 4
f  x   f 0  f 0 x  f 0 x 2  f 0 x 3 
f0 x 
2
3!
4!
h
h

f  x  d x  2 f0 h 
h
2  3
2
f0 h 
f 0 4 h 5 
23
4!  5
Error,
Trapezoid :
Et  O  N int f 0 h 3   O  1 f  b  a 3 


 N2 0

 int

Error,
Simpson :
Es  O  N int f 0 4 h5 
Relative error :
 1
5
 O  4 f 0 4 b  a 
 N int

t, s 
Et , s
f
f n
n 1
 n b  a 
N f
1 ba

2 N int
n data points in
each interval
n=2
n=4
t, s
f n
n 1
 n b  a 
N f
n
f
n 1
b

a
 N m


Nn f
Set scale to
Trapezoid :
Simpson :

ba 1
N  1015 
N  1015 
2/5
2/9
~ 107 ( single prec)
~ 1015 ( double prec)
d  tot
1
1 
 0   n  t , s   m 
dN
N
2 
Min tot :
f n
1
f
m  machine precision
 ro  N  m
Round-off error is random :
 tot   t , s   ro
n = 2,4 for t , s

n 
 f
n 1 
N 
b  a  
f

m


N   m 
 106
 1010/3  2154

2
2 n 1

t,s   m
2
2 n 1
 tot  N  m   m 
 tot  1015 
4/5
 tot  1015 
8/9

1
1
2 n 1
 1012
 1040/3  4.6  1014
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
b
n
a
k 1
Ak   dx
I   d x f ( x ) w( x )  S  Ak f ( xk )
a
 ( x)
( x  xk )  '( xk )
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.
Integral
Polynomial
weight
Limits
 d x f ( x)
Legendre
1
( 1, 1 )
d x e x f ( x)
Hermite
exp( x2 )
( ,  )
Laguerre
exp( x )
( ,  )
( 1x2 )1/2
( 1, 1 )
1
1


2


 dx e
x
f ( x)

1

1
dx
1
1 x
2
f ( x ) Chebyshev I
Proof :
5.6.1. Mapping Integration Points
b
An integral
 F  y d y
1
can be transformed into
1
a
by the linear transform
y  x
a    
Thus
b  
1
  b  a 
2
1
  b  a 
2

f  x 

 f  x d x
1
b  a  F  y 
2
y

1
y   b  a  x  b  a 
2
1
 b  a  x  b  a 
2
dy
1
b  a  d x
2

An integral
 F  y d y
1
can be transformed into
1
0
y
by the linear transform
0
Thus



2

0




1 x
 

f  x 
 f  x d x

2

 0

1  x 
2
1
 1 x 
 1
y 
   

2 1 x 
1 x 2 
dy
F  y
y
  1 x 


2  1 x 

1  x 
2
dx

Similarly, one get the following transforms
1
F  y d y 
 f  x d x
1
interval
Interval
[a,b]
[0,]
W
W
W
[  ,  ]
W 
[b,]
W
[0,b]
W
y
1
b  a 
2

1  x 


2 1 x 
2 1  x 2 
1  x 
2 2

1  x 
1
 b  a  x  b  a 
2
 1 x 
2

2x
1  x2
 1 x 

b
2 1 x 
2
b   2  1
2   x
2
f  x   W F  y  x  
1
1 x
b 1   
2
x
 0
5.7.
Empirical Error Estimate (Ex.5.1)
Answer
Relative error,

numerical  exact
exact
, as a function of N
for the trapezoid, Simpson, & Gaussian methods, in the calculation of
1
I   e t d t  1  e1
0
5.8.
Experimentation
Evaluate
2
2
 sin 1000 x  d x
0
and
 sin 100 x  d x
x
0
What’s wrong ?
5.9.
Higher Order Rules
Let A(h) be the numerical evaluation of an integral with leading error  h2, i.e.,
b
A h    f  x  d x   h2   h4 
a
b

1
1
h
A     f  x  d x   h2   h4 
4
16
2 a

4 h 1
1
A   Ah    f  x  d x   h4 
3 2 3
4
a
b
Romberg’s
extrapolation
see Burden, § 4.5
Download