Vous êtes sur la page 1sur 59

1

Advanced Computational Methods


Numerical Integration
ME753
2


Introduction to Numerical
Integration
Definitions
Upper and Lower Sums
Trapezoid Method (Newton-Cotes Methods)
Simpsons Rules
Romberg Method
Gauss Quadrature
Examples
3
Integration
Indefinite Integrals



Indefinite Integrals of a
function are functions
that differ from each
other by a constant.
}
+ = c
x
dx x
2
2
Definite Integrals



Definite Integrals are
numbers.
2
1
2
1
0
1
0
2
= =
}
x
xdx
4
Fundamental Theorem of Calculus
: for solution form closed No
: for tive antideriva no is There
) f(x) (x) ' F (i.e., f of tive antideriva is
, interval an on continuous is If
2
2
}
}
=
=
b
a
x
x
b
a
dx e
e
F(a) F(b) f (x)dx
F
[a,b] f
5
The Area Under the Curve
}
=
b
a
f(x)dx Area
One interpretation of the definite integral is:
Integral = area under the curve
a b
f(x)
6
Upper and Lower Sums
a b
f(x)
3 2 1 0
x x x x
{ }
{ }
{ }
( )
( )
i i
n
i
i
i i
n
i
i
i i i
i i i
n
x x M P f U sum Upper
x x m P f L sum Lower
x x x x f M
x x x x f m
Def ine
b x x x x a P Partition
=
=
s s =
s s =
= s s s s = =
+

=
+

=
+
+

1
1
0
1
1
0
1
1
2 1 0
) , (
) , (
: ) ( max
: ) ( min
...
The interval is divided into subintervals.

7
Upper and Lower Sums
a b
f(x)
3 2 1 0
x x x x
( )
( )
2
2
integral the of Estimate
) , (
) , (
1
1
0
1
1
0
L U
Error
U L
x x M P f U sum Upper
x x m P f L sum Lower
i i
n
i
i
i i
n
i
i

s
+
=
=
=
+

=
+

8
Example
1
4
3
2
1
4
1
0
3 , 2 , 1 , 0
4
1
1 ,
16
9
,
4
1
,
16
1
16
9
,
4
1
,
16
1
, 0
) intervals equal four ( 4
1 ,
4
3
,
4
2
,
4
1
, 0 :
1
3 2 1 0
3 2 1 0
1
0
2
= =
= = = =
= = = =
=
)
`

=
+
}
i f or x x
M M M M
m m m m
n
P Partition
dx x
i i
9
Example
1
4
3
2
1
4
1
0
( )
( )
8
1
64
14
64
30
2
1
32
11
64
14
64
30
2
1
integral the of Estimate
64
30
1
16
9
4
1
16
1
4
1
) , (
) , (
64
14
16
9
4
1
16
1
0
4
1
) , (
) , (
1
1
0
1
1
0
=
|
.
|

\
|
<
=
|
.
|

\
|
+ =
=
(

+ + + =
=
=
(

+ + + =
=
+

=
+

Error
P f U
x x M P f U sum Upper
P f L
x x m P f L sum Lower
i i
n
i
i
i i
n
i
i
10
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.
11
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.
( )
1
) (
...
2
) (
) ( ) (
... ) (
1 1 2 2
1 0
1 0
+

+ +

+ ~
+ + + ~
+ +
}
} }
n
a b
a
a b
a a b a dx x f
dx x a x a a dx x f
n n
n
b
a
b
a
n
n
b
a
12
Newton-Cotes Methods
Trapezoid Method (First Order Polynomials are used)




Simpson 1/3 Rule (Second Order Polynomials are used)
( )
( )
} }
} }
+ + ~
+ ~
b
a
b
a
b
a
b
a
dx x a x a a dx x f
dx x a a dx x f
2
2 1 0
1 0
) (
) (
13

Trapezoid Method
Derivation-One Interval
Multiple Application Rule
Estimating the Error
Recursive Trapezoid Method


14
Trapezoid Method
) (
) ( ) (
) ( a x
a b
a f b f
a f

+
f(x)
b a
( )
2
) ( ) (
2
) ( ) (
) ( ) (
) (
) (
) ( ) (
) (
) (
2
a f b f
a b
x
a b
a f b f
x
a b
a f b f
a a f
dx a x
a b
a f b f
a f I
dx x f I
b
a
b
a
b
a
b
a
+
=

+
|
.
|

\
|

=
|
.
|

\
|

+ ~
=
}
}
15
Trapezoid Method
Derivation-One Interval
( )
( )
2
) ( ) (
) (
) ( 2
) ( ) ( ) ( ) (
) (
2
) ( ) ( ) ( ) (
) (
) ( ) ( ) ( ) (
) (
) (
) ( ) (
) ( ) (
2 2
2
a f b f
a b
a b
a b
a f b f
a b
a b
a f b f
a a f
x
a b
a f b f
x
a b
a f b f
a a f
dx x
a b
a f b f
a b
a f b f
a a f I
dx a x
a b
a f b f
a f dx x f I
b
a
b
a
b
a
b
a
b
a
+
=

+
|
.
|

\
|

+
|
.
|

\
|

=
|
.
|

\
|

~
|
.
|

\
|

+ ~ =
}
} }
16
Trapezoid Method
) (b f
f(x)
b a
( ) ) ( ) (
2
b f a f
a b
Area +

=
) (a f
17
Trapezoid Method
Multiple Application Rule
a b
f(x)
3 2 1 0
x x x x
s trapezoid the of
areas the of sum ) (
...
segments into d partitione
is b] [a, interval The
2 1 0
=
= s s s s =
}
b
a
n
dx x f
b x x x x a
n
( )
1 2
1 2
2
) ( ) (
x x
x f x f
Area
+
=
x
18
Trapezoid Method
General Formula and Special Case
( )( ) ) ( ) (
2
1
) (
...
equal) y necessaril (not segments into divided is interval the If
1 1
1
0
2 1 0
i i i i
n
i
b
a
n
x f x f x x dx x f
b x x x x a
n
+ ~
= s s s s =
+ +

}
| |
(

+ + ~
=

}

=
+
1
1
0
1
) ( ) ( ) (
2
1
) (
all for
points) base spaced Equaliy ( Case Special
n
i
i n
b
a
i i
x f x f x f h dx x f
i h x x
19
Example
Given a tabulated
values of the velocity of
an object.
Obtain an estimate of
the distance traveled in
the interval [0,3].
Time (s) 0.0 1.0 2.0 3.0
Velocity (m/s) 0.0 10 12 14
Distance = integral of the velocity

}
=
3
0
) ( Distance dt t V
20
Example 1
Time (s) 0.0 1.0 2.0 3.0
Velocity
(m/s)
0.0 10 12 14
( )
29 ) 14 0 (
2
1
12) (10 1 Distance
) ( ) (
2
1
) (
1
0
1
1
1
=
(

+ + + =
(

+ + =
= =

=
+
n
n
i
i
i i
x f x f x f h T
x x h
Method Trapezoid
{ } 3 , 2 , 1 , 0 are points Base
ls subinterva 3 into
divided is interval The
21
Error in estimating the integral
Theorem
) ( ' ' max
12
) (
12
then ) ( e approximat
to used is Method Trapezoid If : Theorem
) (width intervals Equal
on continuous is ) ( ' ' : Assumption
] , [
2
' ' 2
a
x f h
a b
Error
[a,b] where f h
a b
Error
dx x f
h
[a,b] x f
b a x
b
e

s
e

=
=
}

22
Estimating the Error
For Trapezoid Method
? accuracy digit decimal 5 to
) sin( compute to needed
are intervals spaced equally many How
0
}
t
dx x
23
Example
intervals 719
00437 . 0
) (

00437 . 0 10
6
10
2
1
12
1 ) ( ' '
) sin( ) ( ' ' ); cos( ) ( ' ; 0 ;
) ( ' ' max
12
10
2
1
error , ) sin(
5 2
5 2
] , [
2
5
0
= =

>
s s
s s s
= = = =

s
s

}
t
t
t
t
t
h
a b
n
h h
h Error x f
x x f x x f a b
x f h
a b
Error
that so h f ind dx x
b a x
24
Example
( )( )
( )
(

+ + =
=
+ =

=
+
+ +

=
) ( ) (
2
1
) ( ) , (
, all for :
) ( ) (
2
1
) , (
) ( : compute to method Trapezoid Use
0
1
1
1
1 1
1
0
3
1
n
n
i
i
i i
i i i i
n
i
x f x f x f h P f T
i x x h Case Special
x f x f x x P f T Trapezoid
dx x f
x 1.0 1.5 2.0 2.5 3.0
f(x) 2.1 3.2 3.4 2.8 2.7
25
Example
( )
( )
9 . 5
7 . 2 1 . 2
2
1
8 . 2 4 . 3 2 . 3 5 . 0
) ( ) (
2
1
) ( ) (
0
1
1
3
1
=
(

+ + + + =
(
(

+ + ~

}

=
n
n
i
i
x f x f x f h dx x f
x 1.0 1.5 2.0 2.5 3.0
f(x) 2.1 3.2 3.4 2.8 2.7
Example
Use the trapezoidal rule to estimate
( )
}
+ + +
8 . 0
0
5 4 3 2
400 900 675 200 25 2 . 0 dx x x x x x
Solution
% 5 . 89
1728 . 0
2
232 . 0 2 . 0
8 . 0
2
) 8 . 0 ( ) 0 (
) 0 8 . 0 (
2
) ( ) (
) (
=
=
+
=
+
=
+
=
t
f f
b f a f
a b I
c
Example
Use the multiple-application trapezoidal rule for n = 2 to
estimate
( )
}
+ + +
8 . 0
0
5 4 3 2
400 900 675 200 25 2 . 0 dx x x x x x
Solution
% 9 . 34
0688 . 1
4
232 . 0 ) 456 . 2 ( 2 2 . 0
8 . 0
4
) 8 . 0 ( ) 4 . 0 ( 2 ) 0 (
) 0 8 . 0 (
) 2 ( 2
) ( ) ( 2 ) (
) (
2 1 0
=
=
+ +
=
+ +
=
+ +
=
t
f f f
x f x f x f
a b I
c
Computer Algorithms for the
Trapezoidal Rule
30
Recursive Trapezoid Method
f(x)
h a a +
( ) ) ( ) (
2
) 0 , 0 ( R
: interval one on based Estimate
b f a f
a b
a b h
+

=
=
31
Recursive Trapezoid Method
f(x)
h a h a a 2 + +
( )
| | ) ( ) 0 , 0 (
2
1
) 0 , 1 (
) ( ) (
2
1
) (
2
) 0 , 1 ( R
2
: intervals 2 on based Estimate
h a f h R R
b f a f h a f
a b
a b
h
+ + =
(

+ + +

=
Based on previous estimate
Based on new point
32
Recursive Trapezoid Method
f(x)
|
( )
| | ) 3 ( ) ( ) 0 , 1 (
2
1
) 0 , 2 (
) ( ) (
2
1
) 3 ( ) 2 ( ) (
4
) 0 , 2 ( R
4
h a f h a f h R R
b f a f
h a f h a f h a f
a b
a b
h
+ + + + =
(

(
+ +
+ + + + +

=
h a h a a 4 2 + +
Based on previous estimate
Based on new points
33
Recursive Trapezoid Method
Formulas
| |
( )
n
k
a b
h
h k a f h n R n R
b f a f
a b
n
2
) 1 2 ( ) 0 , 1 (
2
1
) 0 , (
) ( ) (
2
) 0 , 0 ( R
) 1 (
2
1

=
(

+ + =
+

=
34
Recursive Trapezoid Method
| |
( )
( )
( )
( )
(

+ + =

=
(

+ + =

=
(

+ + =

=
(

+ + =

=
+

= =

=
=
=
=
) 1 (
2
2
1
2
1
3
2
1
2
1
1
) 1 2 ( ) 0 , 1 (
2
1
) 0 , ( ,
2
........ ..........
) 1 2 ( ) 0 , 2 (
2
1
) 0 , 3 ( ,
2
) 1 2 ( ) 0 , 1 (
2
1
) 0 , 2 ( ,
2
) 1 2 ( ) 0 , 0 (
2
1
) 0 , 1 ( ,
2
) ( ) (
2
) 0 , 0 ( R ,
n
k
n
k
k
k
h k a f h n R n R
a b
h
h k a f h R R
a b
h
h k a f h R R
a b
h
h k a f h R R
a b
h
b f a f
a b
a b h
Example on Recursive Trapezoid
35
error the estimate then R(3,0) computing by ) sin(
: estimate to method Trapezoid Recursive Use
2 /
0
}
t
dx x
n h R(n,0)
0 (b-a)=t/2 (t/4)[sin(0) + sin(t/2)]=0.785398
1 (b-a)/2=t/4 R(0,0)/2 + (t/4) sin(t/4) = 0.948059
2 (b-a)/4=t/8 R(1,0)/2 + (t/8)[sin(t/8)+sin(3t/8)] = 0.987116
3 (b-a)/8=t/16 R(2,0)/2 + (t/16)[sin(t/16)+sin(3t/16)+sin(5t/16)+
sin(7t/16)] = 0.996785
Estimated Error = |R(3,0) R(2,0)| = 0.009669
36
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.

37

Simpsons Rules
Simpsons 1/3 Rule
Simpsons 3/8 Rule

SIMPSONS RULES
More accurate estimate of an integral is obtained if a high-
order polynomial is used to connect the points.
The formulas that result from taking the integrals under
such polynomials are called Simpsons rules.
Simpsons 1/3 Rule
This rule results when a second-order interpolating
polynomial is used.
| |
2
where ) ( ) ( 4 ) (
3
) (
) )( (
) )( (
) (
) )( (
) )( (
) (
) )( (
) )( (
, and Let
) ( ) (
2 1 0
2
1 2 0 2
1 0
1
2 1 0 1
2 0
0
2 0 1 0
2 1
2 0
2
2
0
a b
h x f x f x f
h
I
dx x f
x x x x
x x x x
x f
x x x x
x x x x
x f
x x x x
x x x x
I
x b x a
dx x f dx x f I
x
x
b
a
b
a

= + + ~
(

(


+



+


=
= = -
~ =
}
} }
After integration,
Simpsons 3/8 Rule
This rule results when a third-order interpolating
polynomial is used.
| |
3
where ) ( ) ( 3 ) ( 3 ) (
8
3
, yields This
) ( ) (
3 2 1 0
3
a b
h x f x f x f x f
h
I
dx x f dx x f I
b
a
b
a

= + + + ~
-
~ =
} }
41

Romberg Method
Motivation
Derivation of Romberg Method
Romberg Method
Example
When to stop?

42
Motivation for Romberg Method

Trapezoid formula with a sub-interval h gives an
error of the order O(h
2
).

We can combine two Trapezoid estimates with
intervals h and h/2 to get a better estimate.
43
Romberg Method
First column is obtained
using Trapezoid Method

dx f(x) of ion approximat the improve to combined are
... h/8 h/4, h/2, h, size of intervals method Trapezoid using Estimates
b
a
}
R(0,0)
R(1,0) R(1,1)
R(2,0) R(2,1) R(2,2)
R(3,0) R(3,1) R(3,2) R(3,3)
The other elements
are obtained using
the Romberg Method
44
First Column
Recursive Trapezoid Method
| |
( )
n
k
a b
h
h k a f h n R n R
b f a f
a b
n
2
) 1 2 ( ) 0 , 1 (
2
1
) 0 , (
) ( ) (
2
) 0 , 0 ( R
) 1 (
2
1

=
(

+ + =
+

=
45
Derivation of Romberg Method
| | ... ) 0 , 1 ( ) 0 , ( 4
3
1
) (
2 * 4 1
) 2 ( ...
64
1
16
1
4
1
) 0 , ( ) (
by R(n,0) obtained is estimate accurate More
) 1 ( ... ) 0 , 1 ( ) (
2
method Trapezoid ) ( ) 0 , 1 ( ) (
6
6
4
4
6
6
4
4
2
2
6
6
4
4
2
2
1
2
+ + + =

+ + + + =
+ + + + =

= + =
}
}
}
}

h b h b n R n R dx x f
gives eq eq
eq h a h a h a n R dx x f
eq h a h a h a n R dx x f
a b
h with h O n R dx x f
b
a
b
a
b
a
n
b
a
46
Romberg Method
| |
( )
| | 1 , 1 ) 1 , 1 ( ) 1 , ( 4
1 4
1
) , (
) 1 2 ( ) 0 , 1 (
2
1
) 0 , (
,
2
) ( ) (
2
) 0 , 0 ( R
) 1 (
2
1
> >

=
(
(
(

+ + =

=
+

=
m n m n R m n R m n R
h k a f h n R n R
a b
h
b f a f
a b
m
m
k
n
n
R(0,0)
R(1,0) R(1,1)
R(2,0) R(2,1) R(2,2)
R(3,0) R(3,1) R(3,2) R(3,3)
47
Property of Romberg Method
) ( ) , ( ) (
Theorem
2 2 +
+ =
}
m
b
a
h O m n R dx x f
R(0,0)
R(1,0) R(1,1)
R(2,0) R(2,1) R(2,2)
R(3,0) R(3,1) R(3,2) R(3,3)
) ( ) ( ) ( ) (
8 6 4 2
h O h O h O h O
Error Level
48
Example
| | | |
| |
| |
3
1
2
1
8
3
4
3
1
) 0 , 0 ( ) 0 , 1 ( 4
1 4
1
) 1 , 1 (
1 , 1 ) 1 , 1 ( ) 1 , ( 4
1 4
1
) , (
8
3
4
1
2
1
2
1
2
1
)) ( ( ) 0 , 0 (
2
1
) 0 , 1 ( ,
2
1
5 . 0 1 0
2
1
) ( ) (
2
) 0 , 0 ( , 1
Compute
1
1
0
2
=
(

=
> >

=
=
|
.
|

\
|
+
|
.
|

\
|
= + + = =
= + = +

= =
}
R R R
m n f or m n R m n R m n R
h a f h R R h
b f a f
a b
R h
dx x
m
m
0.5
3/8 1/3
49
Example (cont.)
| |
| |
| |
3
1
3
1
3
16
15
1
) 1 , 1 ( ) 1 , 2 ( 4
1 4
1
) 2 , 2 (
3
1
8
3
32
11
4
3
1
) 0 , 1 ( ) 0 , 2 ( 4
3
1
) 1 , 2 (
) 1 , 1 ( ) 1 , ( 4
1 4
1
) , (
32
11
16
9
16
1
4
1
8
3
2
1
)) 3 ( ) ( ( ) 0 , 1 (
2
1
) 0 , 2 ( ,
4
1
2
2
=
(

=
=
(

= =

=
=
|
.
|

\
|
+ +
|
.
|

\
|
= + + + + = =
R R R
R R R
m n R m n R m n R
h a f h a f h R R h
m
m
0.5
3/8 1/3
11/32 1/3 1/3
50
When do we stop?
at R(4,4) STOP example, for
steps, of number given a After
or
) 1 , ( ) , ( c s n n R n n R
if STOP
51

Gauss Quadrature
Motivation
General integration formula



52
Motivation
( )

=
=
=
~
(
(
(

+ + ~

}
=

=
n and i h
n i h
c where
x f c dx x f
x f x f x f h dx x f
i
n
i
i i
b
a
n
i
n i
b
a
0 5 . 0
1 ,..., 2 , 1
) ( ) (
: as expressed be can It
) ( ) (
2
1
) ( ) (
: Method Trapezoid
0
1
1
0
53
General Integration Formula
integral? the of ion approximat good a gives
formula e that th so select we do How
: Problem
: :
) ( ) (
0
i i
i i
n
i
i i
b
a
x and c
Nodes x Weights c
x f c dx x f

}
=
~
54
Lagrange Interpolation
}

}
}

} }
} }
= ~
|
.
|

\
|
= ~
~
=
=
b
a
i i
n
i
i i
b
a
b
a
i
n
i
i
b
a
n
b
a
n
n
b
a
n
b
a
dx x c where x f c dx x f
dx x f x dx x P dx x f
x x x
x P where
dx x P dx x f
) ( ) ( ) (
) ( ) ( ) ( ) (
,..., , : nodes at the
f(x) es interpolat that polynomial a is ) (
) ( ) (
0
0
1 0

Example
Determine the Gauss Quadrature Formula of

If the nodes are given as (-1, 0 , 1)

Solution: First we need to find l
0
(x), l
1
(x), l
2
(x)

Then compute:

55
}

2
2
) ( dx x f
} } }

= = =
2
2
2 2
2
2
1 1
2
2
0 0
) ( , ) ( , ) ( dx x l c dx x l c dx x l c
Solution
56
) 1 (
3
8
) 0 (
3
4
) 1 (
3
8
) ( for Formula Quadrature Gauss The
3
8
2
) 1 (
,
3
4
) 1 )( 1 ( ,
3
8
2
) 1 (
2
) 1 (
) 1 2 )( 0 2 (
) 1 )( 0 (
) (
) 1 )( 1 (
) 2 1 )( 0 1 (
) 2 )( 0 (
) (
2
) 1 (
) 2 0 )( 1 0 (
) 2 )( 1 (
) (
2
2 -
2
2
2
2
2
1
2
2
0
2
1
0
f f f dx x f
dx
x x
c dx x x c dx
x x
c
x x
x x x x
x x x x
x l
x x
x x x x
x x x x
x l
x x
x x x x
x x x x
x l
+ =
=
+
= = + = =

=
+
=


=
+ =


=

=


=
}
} } }

Using the Gauss Quadrature Formula
57
answer exact same the is which ,
3
16
) 1 (
3
8
) 0 (
3
4
) 1 (
3
8
) 1 (
3
8
) 0 (
3
4
) 1 (
3
8
Formula Quadrature Gauss The
3
16
) ( for e exact valu The
) ( Let : 1 Case
2 2 2
2
2 -
2
2
2 -
2
= + =
+ =
= =
=
} }
f f f
dx x dx x f
x x f
Using the Gauss Quadrature Formula
58
answer exact same the is which , 0 ) 1 (
3
8
) 0 (
3
4
) 1 (
3
8
) 1 (
3
8
) 0 (
3
4
) 1 (
3
8
Formula Quadrature Gauss The
0 ) ( for e exact valu The
) ( Let : 2 Case
3 3 3
2
2 -
3
2
2 -
3
= + =
+ =
= =
=
} }
f f f
dx x dx x f
x x f
59
Improper Integrals
} }
} }
|
|
|
|
|
.
|

\
|
|
.
|

\
|
=
>
|
.
|

\
|
=


1
0
2 2
1
2
1
1
2
a
1
1 1 1
:
function. new the on method apply the and
) 0 assuming ( ,
1 1
) (
following the like mation a transfor Use
) or is limits the of (one integrals improper e approximat
to directly used be cannot earlier discussed Methods
dt
t
t
dx
x
Example
ab dt
t
f
t
dx x f
a
b
b

Vous aimerez peut-être aussi