Kuliah5.1 - (Integrasi Numerik)
Kuliah5.1 - (Integrasi Numerik)
Kuliah5.1 - (Integrasi Numerik)
Roger Crawfis
Outline
• Definite Integrals
• Lower and Upper Sums
– Reimann Integration or Reimann Sums
• Uniformly-spaced samples
– Trapezoid Rules
– Simpson’s Rules
– Adaptive Simpson’s Scheme
• Non-uniformly spaced samples
– Gaussian Quadrature Formulas
where x b a
n
a
i 1
f ( x) M x
x0 i 0
i i 1 xi
• where
M i sup f ( x) : xi x xi 1 Supremum - least
upper bound
• Graphically:
x0 x1 x2 x3 x4
i 0
i i 1 i
x0
• where
mi inf f ( x) : xi x xi 1
Infimum - greatest
lower bound
• Graphically
x0 x1 x2 x3 x4
m x
i 0
i i 1 xi f ( x) M i xi 1 xi
i 0
x0
• Graphically
x0 x1 x2 x3 x4
x0 x3 x5 x7 x9
x0 x5 x7 x9 x11
x0 x3 x5 x7 x9
February 4, 2020 OSU/CSE 541 15
Lab1 and Integration
I f x dx p1 x dx
b b
a a
f b f a
f a x a dx
b
I
a ba
Trapezoid Rule
f(b)
I
b a
f a f b
f(a)
2
• Improvement?
x0 x1 x2 x3 x4
2
I e dx x2
0
b a
f a f b (2 0)
f (2) f (0)
2 2
1 (e 4 e0 ) 1.0183
23 f 0 f 2
Et Ea 0.58
12 2
February 4, 2020 OSU/CSE 541 24
More intervals, better result [error O(h2)]
7 7
6
n=2 6
n=3
5 5
4 4
3 3
2 2
1 1
0 0
3 5 7 9 11 13 15 3 5 7 9 11 13 15
7 7
6
n=4 6
n=8
5 5
4 4
3 3
2 2
1 1
0 0
3 5 7 9 11 13 15 3 5 7 9 11 13 15
a h a a 2h a h
f a f a h f a h f a 2h
2 2
b b h
.... f b h f b
2
• from 40
a=0.2 35
to 30
b=0.8 25
20
15
10
0
0 0.2 0.4 0.6 0.8 1 1.2
February 4, 2020 OSU/CSE 541 30
Example
12
f x
0.2
f dx
0.8 0.2
f (0.8) f (0.2)
131.6
0.8 0.2
February 4, 2020 OSU/CSE 541 32
Example
Et f 2
f
12 12n
1
131.6 0.8 0.2 2.37
3
12
35
30
25
20
15
10
0
0 0.2 0.4 0.6 0.8 1 1.2
35
30
25
20
15
10
0
0 0.2 0.4 0.6 0.8 1 1.2
35
30
25
20
15
10
0
0 0.2 0.4 0.6 0.8 1 1.2
f x, y dxdy Ai f , y dy
0 0 0 i 0 n
i
n 1
Ai f , y dy
i 0 0 n
n
i j n
Ai Aj f ,
i 0 j 0 n n
n
i j
n
Ai Aj f ,
i 0 j 0 n n
February 4, 2020 OSU/CSE 541 39
Multi-dimensional Integration
1 2 2 2 2 2 1
• If the dimension is high, this leads to a
significant amount of additional work in
going from hh/2.
– Remember this for Monte-Carlo Integration.
• Recall:
xn x0m1 x0m1m2 xn
x0
f ( x)dx
x0
pm1 ( x)dx
x0m1
pm2 ( x)dx ...
xnmn
pmn ( x)dx
x x1 x x2 x x0 x x2 f x
f x0
x2
I
x0 x x x x 1
0 1 0 2 x1 x0 x1 x 2
x x0 x x1
f x2 dx
x2 x0 x2 x1
Quadratic
8 Polynomial
0
3 5 7 9 11 13 15
f x0 4 f x1 f x2
I b a
6
width
average height
Et
h 5 4
f
b a 4
5
f 5
90 2880
O(h )
ba
h
2
20
15
10
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5
-5
x 0 x 2 x n 2
I b a
i 1,3,5 j 2,4,6
3n
n+1 data points, an odd number
February 4, 2020 OSU/CSE 541 55
Composite Simpson’s 1/3 Rule
4 1 coefficients on
1
4 1 i=n numerator
1 1
1 4
i=0
• Error estimate: Et
h 5 4
f
90
I f ( x )dx h f x0 4 f ( x1 ) f x2
2 1
0 3
(0.4)
f 0 4 f (0.4) f 0.8
3
1.36746667
Exact integral is 1.64053334
February 4, 2020 OSU/CSE 541 60
Error
0.45 0.45
Et Ea f 4
x1 f 4
0.4 0.27306667
90 90
middle point
3n
f (0) 4 f (0.2) 2 f (0.4) 4 f (0.6) f (0.8)
0.8 0
(3)( 4)
0.2 4(1.288 3.464) 2(2.456) 0.232
0.8
12
1.6234667 Exact integral is 1.64053334
February 4, 2020 OSU/CSE 541 63
Error
max
x 0,0.8
f ( 4)
( x) f ( 4)
(0) 21600
f ( 4)
(0.4) 2400
f ( x) p3 ( x) a0 a1 x a2 x 2 a3 x 3
I f x dx p3 x dx
x3 x3
x0 x0
I h f x0 3 x1 3 f x2 f x3
3
8
ba
h
3
Simpson’s 1/3
Simpson’s 3/8
f x dx f a 4 f x1 f b
a 3
h
b
f x dx f a 4 f x1 2 f x2 4 f x3 f b
a 6
f x dx f a 4 f x1 f x2 , and
a 6 2
h
b
f x dx f x2 4 f x3 f b , where
c 6 2
ab
c x2
2
• The left and the right are within one-half of the
error.
February 4, 2020 OSU/CSE 541 76
Adaptive Simpson’s Scheme
ba ab
S a, b f a 4 f f b , and
6 2
1 b a 4
5
E a, b f
90 2
S S a, b , E E a , b
1 1
• Now, since
E 2
E a, c E c, b
• We can solve for E(2) in terms of E(1).
5 5
1 h / 2 4 1 h / 2 4
E
2
f f
90 2 90 2
5
1 1 h 4 1 1
4 f E
2 90 2 16
I S 2
E 2
S 2
15
1 2
S S 1
February 4, 2020 OSU/CSE 541 82
Adaptive Simpson’s Scheme
S 15
formula: 2 1
S
I=Ileft + Iright
1
i 1
i i
ci : weighting factors
xi : sampling points selected optimally New!!
1
i 1
• f(x)=1 1dx 2
1
c1 f x1 c2 f x2 c1 x1 c2 x2
– Linear 1
• f(x)=x xdx 0
1
– Quadratic 2
1
1
2 2 2
• f(x)=x2
x dx c1 f x1 c 2 f x 2 c x
1 1 c x
2 2
3
– Cubic
x 3 dx 0 c1 f x1 c2 f x2 c1 x1 c2 x2
1
3 3
• f(x)=x3 1
ax bx cx d dx a x dx b x dx c xdx d dx
3 2 3 2
1 1 1 1 1
1 3 1 3 1 2 1 2 1 1
a b c d 1 1
3 3 3 3 3 3
ax bx cxd
1
3 2 3
1
3
-0.577 0.577
x
-1 1
February 4, 2020 OSU/CSE 541 108
Example
• Integrate f(x) from a = 0 to b = 0.8
f ( x) 0.2 25x 200 x 2 675x 3 900 x 4 400 x5
• Transform from [0, 0.8] to [-1, 1]
b (b a ) 1 (b a ) x b a
a
f (t )dt
2 1
f
2
dx
1
February 4, 2020 OSU/CSE 541 109
Example
• Solving
I 0.4 f 0.4t 0.4 dt
1
1
1
t 1 / 3
I 0.51674055 1.30583723 1.82257778
Exact integral is 1.64053334
February 4, 2020 OSU/CSE 541 110
Higher-order Gaussian Quadrature
1
i 1
c1 f x1 c2 f x2 c3 f x3 c1 c2 c3
1
1dx 2
1
c1 f x1 c2 f x2 c3 f x3 c1 x1 c2 x2 c3 x3
1
xdx 0
1
2
1
1
2 2 2 2
x dx c1 f x1 c2 f x 2 c3 f x3 c x
1 1 c x
2 2 c x
3 3
3
x 3dx 0 c1 f x1 c2 f x2 c3 f x3 c1 x1 c2 x2 c3 x3
1
3 3 3
1
2
1
1
4 4 4 4
x dx c1 f x1 c2 f x 2 c3 f x3 c x
1 1 c x
2 2 c x
3 3
5
x 5dx 0 c1 f x1 c2 f x2 c3 f x3 c1 x1 c2 x2 c3 x3
1
5 5 5
1
x
-0.775 0.775
February 4, 2020 -1 OSU/CSE 541 1 114
Example
3 8 3
f 0
5 5
I
f f
9
5 9 9 5
1
n 2 3 4 5 6
ci 1.0 0.5555555556 0.3478548451 0.2369268850 0.1713245
1.0 0.8888888889 0.6521451549 0.4786286705 0.3607616
0.5555555556 0.6521451549 0.5688888889 0.4679139
0.3478548451 0.4786286705 0.4679139
0.2369268850 0.3607616
0.1713245
• Problems:
– If we add more data points, like doubling the
number of sample points.