Professional Documents
Culture Documents
MAFE208IU-L10 - Numerical Integration
MAFE208IU-L10 - Numerical Integration
Lecture 2:
Numerical Integration
Motivations
❖ Many integrals cannot be evaluated by
integration techniques, for example:
1 2 2
sin x
e 1 x dx, x dx, e
x 2
x ( x − y )2
dx, dA,...
0 1 D
Complicated function
MAFE208IU-L10 Function given in tabular form 3
Trapezoidal Rule: single application
b
b
a
f ( x)dx =
i =1 xi −1
f ( x)dx
x
n
f ( xi ) + f ( xi −1 ) x0 x1 x2 x3
( xi − xi −1 ) a b
i =1 2
MAFE208IU-L10 5
Trapezoidal Rule:
General Formula and Special case
a) If the interval is divided into n segments (not necessarily equal):
n
[ a, b] = [ xi −1 , xi ], where a = x0 x1 x2 ... xn = b, then
i =1
n
f ( xi ) + f ( xi −1 )
( x − x )
b
a
f ( x)dx
i =1
i i −1
2
b−a
b) Special Case ( Equally spaced base points): xi − xi −1 = h, i h =
n
h n −1
f (a ) + 2 f ( xi ) + f (b)
b
a
f ( x)dx
2 i =1
MAFE208IU-L10 6
Example
Money flows into a
Time t (hours) 0.0 1.0 3.0 4.0
bank at different times
is given in the Table Flow rate R 0.0 10 12 14
(mills $/hour)
10 + 0 12 + 10 14 + 12
F= + (3 − 1) + = 5 + 22 + 13 = 40 (mills $)
2 2 2
MAFE208IU-L10 7
Trapezoidal Rule: Error Estimate
Assumption: f ''( x) is continuous on [a,b]
b−a
Theorem: If Trapezoidal Rule for h = is used to
n
b
approximate a
f ( x)dx then
b − a 2 ''
Error = − h f ( ) where [a,b]
12
b−a 2
Error h max f ''( x)
12 x[ a ,b ]
MAFE208IU-L10 8
Example: How large do we have to choose n in Trapezoidal rule for
1
approximating
0
sin( x)dx to make sure that error 10−5
2
Solution
b−a 2
Error h max f ''( x)
12 x[ a ,b ]
12 2 n
3/2
n 105/2 = 718.9. n 719
MAFE208IU-L10
6 9
Exercise
f ( x)dx f
a a
p ( x)dx
fp =
( x − x1 )(x − x2 )
f ( x0 ) +
( x − x0 )(x − x2 )
f ( x1 ) +
( x − x0 )(x − x1 )
f ( x2 )
(x0 − x1 )(x0 − x2 ) (x1 − x0 )(x1 − x2 ) (x2 − x0 )(x2 − x1 )
By substitution u=x-x0 we have
f ( x0 ) + 4 f ( x1 ) + f ( x2 )
x2 x2
f ( x)dx f p ( x)dx = ( x2 − x0 )
x0 x0 6
MAFE208IU-L10
Simpson’s 1/3Rule: Multiple Applications
n /2 x2 i
b
a
f ( x)dx =
i =1 x2 ( i −1)
f ( x)dx
i =1 6
Simpson’s 1/3 Rule: Special Case
Data are equally spaced:
b−a
xi = a + ih, i = 0,1, 2,..., n, h = , n: even integer
n
b n −1 n−2
h
f ( x)dx f (a ) + 4 f ( xi ) + 2 f ( xi ) + f (b)
3 i =1 i =2
a
i = odd i = even
MAFE208IU-L10 13
Example
Use 4-segment Simpson’s 1/3 Rule to approximate the
distance covered by a rocket from t= 8 to t=30 as given by
30
140000
x = 2000 ln − 9.8t dt
8 140000 − 2100t
MAFE208IU-
14
L10
Solution
f (t4 ) = f (30)
MAFE208IU-L10 15
Solution (cont.)
n −1 n−2
h
x= f (t0 ) + f (tn ) + 4 f (ti ) + 2 f (ti )
3 i =1 i =2
i = odd i = even
3 2
5.5
= f (8) + f (30) + 4 f (ti ) + 2 f (ti )
3 i =1 i =2
i = odd i = even
22
= f (8) + 4 f (t1 ) + 4 f (t 3 ) + 2 f (t 2 ) + f (30)
12
MAFE208IU-L10 16
Solution (cont.)
cont.
11
= f (8) + 4 f (13.5) + 4 f (24.5) + 2 f (19) + f (30)
6
11
= 177.2667 + 4(320.2469) + 4(676.0501) + 2(484.7455) + 901.6740
6
= 11061.64 m
MAFE208IU-L10 17
Solution (cont.)
11061.34 − 11061.64
t = 100%
11061.34
= 0.0027%
MAFE208IU-L10 18
Solution (cont.)
Table 1: Values of Simpson’s 1/3rd Rule for Example 2 with multiple segments
MAFE208IU-L10 19
Error in the Multiple Segment
Simpson’s Rule
Assumption: f (4) ( x) is continuous on [a,b]
b−a
Theorem: If Simpson's Method for h = is used to
n
b
approximate a
f ( x)dx then
b − a 4 (4)
Er = − h f ( ) where [a,b]
180
b−a 4
Er h max f (4) ( x)
180 x[ a ,b ]
MAFE208IU-L10 20
Simpso
n’s 3/8
Rule
fp =
( x − x1 )(x − x2 )(x − x3 )
f ( x0 ) +
( x − x0 )(x − x2 )(x − x3 )
f ( x1 )
(x0 − x1 )(x0 − x2 )(x0 − x3 ) (x1 − x0 )(x1 − x2 )(x1 − x3 )
+
(x − x0 )(x − x1 )(x − x3 ) f ( x ) + (x − x0 )(x − x1 )(x − x2 ) f ( x )
(x2 − x0 )(x2 − x1 )(x2 − x3 ) 2 (x3 − x0 )(x3 − x1 )(x3 − x2 ) 3
21
Simpson’s 3/8 Rule
By substitution u=x-x0 we have
x3 − x0
b
3h
f ( x)dx f ( x0 ) + 3 f ( x1 ) + 3 f ( x2 ) + f ( x3 ) h =
a
8 3
3 5 (4)
Er − h f ( )
80 22
Numerical Integration in a Two
Dimensional Domain
d(x) yN ,N
y0 , N y1, N
yN ,2
y0 , 2 y1, 2
y N ,1
y1,1
y0,1
y N ,0
c(x) y1, 0
y0 , 0
a = x0 x1 xN −1 b = xN
• A double integration in the domain is written as
b d ( x )
I = f ( x, y )dy dx
a
c( x)
24
Procedure: d ( x)
G ( xi ) = f ( x , y)dy,
c ( xi )
i
25
• Step 3: Divided the domain of integration c( xi ), d ( xi )
into N equi-spaced intervals with the interval size
hy =
d ( xi ) − c( xi )
N
So, the grid points denoted by yi ,0 , yi ,1 ,, yi , N
26
• Step 5: By applying numerical integration (for example trapezoidal
rule) in one-dimensional domain we have the solution of double
integration is
hx N −1
I= G( x0 ) + 2 G( xi ) + G( xN )
2 i =1
27
A simple method
Let D be a bounded region,
enclosed in a rectangle R
Define
f ( x, y), if ( x, y) D
F ( x, y ) =
0, if ( x, y) D
Improper Integrals
1
1/ a
1
t = 1/ x, a
f ( x)dx =
0
t2
f dt
t
x
x0 x1 x2 x3
f (a ) = , use a rule for a ' = x1 x2 ... xn = b 29