Numerical Analysis
Numerical Analysis
Integration
Definitions
Upper and Lower Sums
Trapezoid Method (Newton-Cotes Methods)
Gauss Quadrature
Examples
1
Integration
Indefinite Integrals Definite Integrals
2 1 2 1
x x 1
x dx 2 c 0 xdx 2
2
0
2
Fundamental Theorem of Calculus
If f is continuous on an interval [a,b] ,
F is antiderivative of f (i.e., F ' (x) f(x) )
b
a
f(x)dx F(b) F(a)
x2
There is no antiderivative for : e
b
No closed form solution for : e dx x2
a
3
The Area Under the Curve
One interpretation of the definite integral is:
Integral = area under the curve
f(x)
b
Area f(x)dx
a
a b
4
Upper and Lower Sums
The interval is divided into subintervals.
Partition P a x0 x1 x2 ... xn b
Define
mi min f ( x) : xi x xi 1 f(x)
M i max f ( x) : xi x xi 1
n 1
Lower sum L( f , P ) mi xi 1 xi
i 0
n 1
Upper sum U ( f , P ) M i xi 1 xi
i 0 x0 x1 x2 x3
a b
5
Upper and Lower Sums
n 1
Lower sum L( f , P ) mi xi 1 xi
i 0
n 1
Upper sum U ( f , P ) M i xi 1 xi f(x)
i 0
L U
Estimate of the integral
2
U L
Error
2
x0 x1 x2 x3
a b
6
Example
1
0
x 2 dx
1 2 3
Partition : P 0, , , ,1
4 4 4
n 4 (four equal intervals)
1 1 9
m0 0, m1 , m2 , m3
16 4 16
1 1 9
M 0 , M1 , M 2 , M 3 1
16 4 16
1 1 1 3
xi 1 xi for i 0,1, 2, 3 0 1
4 4 2 4
7
Example
n 1
Lower sum L( f , P) mi xi 1 xi
i 0
1 1 1 9 14
L( f , P ) 0
4 16 4 16 64
n 1
Upper sum U ( f , P) M i xi 1 xi
i 0
11 1 9 30
U ( f , P) 1
4 16 4 16 64
1 30 14 11
Estimate of the integral
2 64 64 32
1 30 14 1
Error
2 64 64 8 1 1 3
0 1
4 2 4
8
Upper and Lower Sums
• Estimates based on Upper and Lower
Sums are easy to obtain for monotonic
functions (always increasing or always
decreasing).
• For non-monotonic functions, finding
maximum and minimum of the function
can be difficult and other methods can be
more attractive.
9
Newton-Cotes Methods
In Newton-Cote Methods, the function
is approximated by a polynomial of
order n.
Computing the integral of a polynomial
is easy.
a
b
f ( x)dx
a
b
a 0 a1 x ... an x dx
n
b (b 2 a 2 ) (b n 1 a n 1 )
a
f ( x)dx a0 (b a ) a1
2
... an
n 1
10
Newton-Cotes Methods
Trapezoid Method (First Order Polynomials are used)
b b
a f ( x)dx
a
a0 a1x dx
a
b
f ( x)dx
b
a
a0
2
a1x a2 x dx
11
Trapezoid Method
Derivation-One Interval
Multiple Application Rule
Estimating the Error
Recursive Trapezoid Method
12
Trapezoid Method
b
I f ( x)dx
f (b) f (a) a
f (a) ( x a)
ba b f (b) f (a)
I f (a) ( x a) dx
f(x)
a
ba
b
f (b) f (a )
f (a) a x
ba a
2 b
f (b) f (a ) x
ba 2 a
a b f (b) f (a)
b a
2
13
Trapezoid Method
Derivation-One Interval
b
b f (b) f (a )
I f ( x)dx f (a ) ( x a ) dx
a a
ba
b f (b) f (a ) f (b) f (a )
I f (a) a x dx
a
ba ba
b 2 b
f (b) f (a ) f (b) f (a ) x
f (a) a x
ba a ba 2 a
f (b) f (a ) f (b) f (a ) 2
f (a) a b a (b a 2 )
ba 2(b a )
f (b) f (a )
b a
2
14
Trapezoid Method
f(x)
f (b)
f (a )
ba
Area f (a) f (b)
2
a b
15
Trapezoid Method
Multiple Application Rule
f ( x2 ) f ( x1 )
Area x2 x1
f(x) 2
The interval [a, b] is
partitioned into n segments
a x0 x1 x2 ... xn b
b
a
f ( x)dx sum of the areas
of the trapezoids
x
x0 x1 x2 x3
a b
16
Trapezoid Method
General Formula and Special Case
Obtain an estimate of
the distance traveled in
the interval [0,3].
Trapezoid Method
h xi 1 xi 1
n 1 1
T h f ( xi ) f ( x0 ) f ( xn )
i 1 2
1
Distance 1(10 12) (0 14) 29
2
19
Error in estimating the integral
Theorem
Assumption : f ' ' ( x) is continuous on [a,b]
Equal intervals (width h)
Theorem : If Trapezoid Method is used to
b
approximate a
f ( x)dx then
b a 2 ''
Error h f ( ) where [a,b]
12
ba 2
Error h max f ' ' ( x)
12 x[ a ,b ]
20
Estimating the Error
For Trapezoid Method
21
Example
1
sin( x )dx, find h so that error 105
2
0
ba 2
Error h max f ' ' ( x )
12 x[ a ,b ]
b ; a 0; f ' ( x ) cos( x ); f ' ' ( x ) sin( x )
2 1
f ' ' ( x ) 1 Error h 105
12 2
2 6
h 105 h 0.00437
(b a )
n 719 intervals
h 0.00437 22
Example
x 1.0 1.5 2.0 2.5 3.0
3
Use Trapezoid method to compute : 1
f ( x) dx
n 1
1
Trapezoid T ( f , P ) xi 1 xi f ( xi 1 ) f ( xi )
i 0 2
3 n1 1
1 f ( x)dx h f ( xi ) f ( x0 ) f ( xn )
i 1 2
1
0.5 3.2 3.4 2.8 2.1 2.7
2
5.9
24
Recursive Trapezoid Method
Estimate based on one interval :
f(x)
h ba
ba
R (0,0) f ( a ) f (b)
2
a ah
25
Recursive Trapezoid Method
Estimate based on 2 intervals :
f(x)
ba
h
2
ba 1
R (1,0) f ( a h ) f ( a ) f ( b )
2 2
1
R(1,0) R(0,0) h f (a h )
2
1
R(2,0) R(1,0) h f (a h) f (a 3h)
2
a a 2h a 4h
Based on previous estimate
Based on new points
27
Recursive Trapezoid Method
Formulas
ba
R (0,0) f (a) f (b)
2
1 2 ( n1)
R(n,0) R(n 1,0) h f a (2k 1)h
2 k 1
ba
h n
2
28
Recursive Trapezoid Method
ba
h b a, R (0,0) f (a) f (b)
2
ba 1 1
h , R (1,0) R(0,0) h f a (2k 1)h
2 2 k 1
ba 1 2
h 2 , R (2,0) R(1,0) h f a (2k 1)h
2 2 k 1
2
2
ba 1
h 3 , R(3,0) R (2,0) h f a (2k 1)h
2 2 k 1
..................
2
( n 1 )
ba 1
h n , R(n,0) R (n 1,0) h f a (2k 1)h
2 2 k 1
29
Example on Recursive Trapezoid
Use Recursive Trapezoid method to estimate :
/2
0
sin( x )dx by computing R(3,0) then estimate the error
n h R(n,0)
0 (b-a)=/2 (/4)[sin(0) + sin(/2)]=0.785398
1 (b-a)/2=/4 R(0,0)/2 + (/4) sin(/4) = 0.948059
2 (b-a)/4=/8 R(1,0)/2 + (/8)[sin(/8)+sin(3/8)] = 0.987116
3 (b-a)/8=/16 R(2,0)/2 + (/16)[sin(/16)+sin(3/16)+sin(5/16)+
sin(7/16)] = 0.996785
30
Advantages of Recursive Trapezoid
Recursive Trapezoid:
Gives the same answer as the standard
Trapezoid method.
Makes use of the available information to
reduce the computation time.
Useful if the number of iterations is not
known in advance.
31
Gauss Quadrature
Motivation
General integration formula
32
Motivation
Trapezoid Method :
b n 1
1
f ( x )dx h f ( xi ) f ( x0 ) f ( xn )
2
a i 1
It can be expressed as :
b n
f ( x )dx ci f ( xi )
a
i 0
h i 1,2,..., n 1
where ci
0.5 h i 0 and n
33
General Integration Formula
b n
f ( x )dx ci f ( xi )
a
i 0
ci : Weights xi : Nodes
Problem :
How do we select ci and xi so that the formula
gives a good approximation of the integral?
34
Lagrange Interpolation
b b
a
f ( x)dx Pn ( x)dx
a
35
Example
Determine the Gauss Quadrature Formula of
2
Then compute:
2 2 2
2 2 2
36
Solution
( x x1)( x x 2) x ( x 1)
l0 ( x )
( x 0 x1)( x 0 x 2) 2
( x x 0)( x x 2)
l1( x ) ( x 1)( x 1)
( x1 x 0)( x1 x 2)
( x x 0)( x x1) x ( x 1)
l2 ( x )
( x 2 x 0)( x 2 x1) 2
2 2 2
x ( x 1) 8 4 x ( x 1) 8
c0 dx , c1 ( x 1)( x 1)dx , c2 dx
2 3 3 2 3
2 2 2
2
8 4 8
The Gauss Quadrature Formula for f ( x )dx f ( 1) f (0) f (1)
3 3 3
-2 37
Using the Gauss Quadrature Formula
Case 1 : Let f ( x ) x 2
2 2
2 16
The exact value for f ( x )dx x dx
3
-2 -2
8 4 8
The Gauss Quadrature Formula f ( 1) f (0) f (1)
3 3 3
8 2 4 2 8 2 16
( 1) (0) (1) , which is the same exact answer
3 3 3 3
38
Using the Gauss Quadrature Formula
Case 2 : Let f ( x ) x 3
2 2
-2 -2
8 4 8
The Gauss Quadrature Formula f ( 1) f (0) f (1)
3 3 3
8 3 4 3 8 3
( 1) (0) (1) 0, which is the same exact answer
3 3 3
39
Improper Integrals
Methods discussed earlier cannot be used directly to
approximate improper integrals (one of the limits is or )
Use a transformation like the following
1
b
a 1 1
f ( x )dx 2
f dt , (assuming ab 0)
a
1 t t
b
and apply the method on the new function.
1
1 1 1
Example : 2
dx 2 2
dt
1
x 0
t 1
t
40