Download as pdf or txt
Download as pdf or txt
You are on page 1of 33

Chapter 4: Numerical

Differentiation and 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

❖ Integrand functions are in tabular form, for example:


Time t 1.0 2.0 4.0 5.0

Money flow 6.0 8.0 9.5 12.8


rate R
5
Money flow =
MAFE208IU-L10  1
R (t ) dt 2
Newton-Cotes Methods
• In Newton-Cote Methods, the function is
approximated by a polynomial of order p
• Computing the integral of a polynomial is
easy.
f ( x)  f p ( x) = a0 + a1 x + ... + a p x p
b b

a
f ( x)dx   f p ( x) dx
a

Complicated function
MAFE208IU-L10 Function given in tabular form 3
Trapezoidal Rule: single application
b

f (b) − f (a) I =  f ( x)dx


f (a) + ( x − a)
a
b−a b  f (b) − f (a ) 
I    f (a) + ( x − a ) dx
a
 b−a 
f(x) b
 f (b) − f (a ) 
=  f (a) − a x
 b−a  a
2 b
f (b) − f (a ) x
+
b−a 2 a
a b f (b) + f (a )
= (b − a )
2
MAFE208IU-L10 4
Trapezoidal Rule: Multiple Application
The interval [a,b] is
partitioned into n segments
f(x)
a = x0  x1  x2  ...  xn = b
b
 a
f ( x)dx  sum of the areas
of the trapezoids
n xi


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)

Estimate money flow in these 4 hours


3
R(ti ) + R (ti −1 )
R (t )dt   ( ti − ti −1 )
4
F =
0
i =1 2

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 ]

b =  ; a = 0; f '( x) = cos( x); f ''( x) = − sin( x)



f ''( x)  1, x  [0,  ]  Error  h2
12
1  2

6
We require h  10  2 = h  10−5
2 −5 2

12 2 n 
 3/2
n 105/2 = 718.9.  n  719
MAFE208IU-L10
6 9
Exercise

Given the integral


2
I =  ln(2 x + 1)dx
0

a) Evaluate I using trapezoidal rule with n=6. Find


the relative error.
b) How large do we have to choose the integer n in
trapezoidal rule to make sure that the error
cannot exceed 10-8
MAFE208IU-L10 10
Simpson’s 1/3 Rule
b b

 f ( x)dx   f
a a
p ( x)dx

where fp is a quadratic polynomial


interpolation, that is
11

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

x0 = a  x1  x2  ...  xn = b, i = 0,1, 2,..., n, n : even

n /2 x2 i

 
b
 a
f ( x)dx =
i =1 x2 ( i −1)
f ( x)dx

f ( x2(i −1) ) + 4 f ( x2i −1 ) + f ( x2i )


12

  ( x2i − x2( i −1) )


n /2

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  

a) Use four segment Simpson’s Rule to find the approximate


value of x.
b) Find the true error
c) Find the absolute relative true error

MAFE208IU-
14
L10
Solution

a) Using 4-segment Simpson’s 1/3 Rule,


30 − 8
h= = 5.5 𝑡𝑖 = 8 + 𝑖ℎ,
4
So
f (t 0 ) = f (8)
f (t1 ) = f (8 + 5.5) = f (13.5)
f (t 2 ) = f (13.5 + 5.5) = f (19)
f (t 3 ) = f (19 + 5.5) = f (24.5)

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.)

b) In this case, the true error is

Et = 11061.34 − 11061.64 = −0.30 m

c) The absolute relative true error

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

n Approximate Value Et |Єt |


2 11065.72 4.38 0.0396%
4 11061.64 0.30 0.0027%
6 11061.40 0.06 0.0005%
8 11061.35 0.01 0.0001%
10 11061.34 0.00 0.0000%

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

Similar to 1/3 Simpson’s method, f approximately by function fp


where fp is a cubic polynomial interpolation, that is

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) 

• The numerical integration of above equation is to


reduce to a combination of one-dimensional problems

24
Procedure: d ( x)

• Step 1: Define G ( x) =  f ( x, y)dy


c( x)
b
So, the solution is I =  G ( x)dx
a

• Step 2: Divided the range of integration [a,b] into


N equispaced intervals with the interval size
b−a
hx =
N
So, the grid points will be denoted by x0 , x1 ,, xN
and then we have d (x ) i

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

• Step 4: By Applying numerical integration for one-dimensional


(for example the trapezoidal rule) we have
hy  N −1 
G ( xi ) =  f ( xi , yi ,0 ) + 2 f ( xi , yi , j ) + f ( xi , yi , N ) 
2 j =1 
for i = 0,1,2,, 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

 f ( x, y)dA = F ( x, y)dA


D R

Equally spaced data rules can be applied


f(x)

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

use right-end point rule in [ x0 , x1 ]


For example, trapezoidal rule:
n
f ( xi ) + f ( xi −1 )
f ( x)dx  f ( x1 ) ( x1 − x0 ) +  ( xi − xi −1 )
b
 a
MAFE208IU-L10 i =2 2
Exercise 1

Trapezoidal Rule: Given the integral


 /2
I=  sin( x )dx
2

a) Evaluate I with n=6. Estimate the error.


b) How large do we need to choose n so that the
|Er| ≤ 10-8
MAFE208IU-L10 30
Exercise 2

Simpson’s 1/3 rule: Given the integral


 /2
I=  sin( x )dx
2

a) Evaluate I with n=6. Estimate the error.


b) How large do we need to choose n so that the
|Er| ≤ 10-8
MAFE208IU-L10 31
Exercise 3

Simpson’s 3/8 rule: Given the integral


 /2
I=  sin( x )dx
2

a) Approximate I. Estimate the error.


b) Use it in conjunction with Simpson’s 1/3 rule
to approximate I for 5 segments
MAFE208IU-L10 32
Quiz
1
Given the integral I = e − x2
dx
0

a) Evaluate I using Simpson’s 1/3 rule with n=6.


b) How large do we need to choose n so that
Simpson’s 1/3 rule gives |Er| ≤ 10-8
c) Approximate I using Simpson’s 3/8 rule. Use it
in conjunction with Simpson’s 1/3 rule to
approximate I for 5 segments
MAFE208IU-L10 33

You might also like