Sunteți pe pagina 1din 42

USC

Numerical Integration
Basic Numerical Integration
We want to find integration of functions of various
forms of the equation known as the Newton Cotes
integration formulas.
Trapezoidal Rule
Simpsons Rule
1/3 Rule
3/8 Rule
Midpoint
Gaussian Quadrature
USC
Basic Numerical Integration
Weighted sum of function values
) x ( f c ) x ( f c ) x ( f c
) x ( f c dx ) x ( f
n n 1 1 0 0
i
n
0 i
i
b
a
+ + + =
~
=

x
0
x
1
x
n
x
n-1

x
f(x)
USC
0
2
4
6
8
10
12
3 5 7 9 11 13 15
Numerical Integration
Idea is to do integral in small parts, like the way you first learned
integration - a summation
Numerical methods just try to make it faster and more accurate
USC
Numerical Integration
Newton-Cotes Closed Formulae -- Use
both end points
Trapezoidal Rule : Linear
Simpsons 1/3-Rule : Quadratic
Simpsons 3/8-Rule : Cubic
Booles Rule : Fourth-order
Newton-Cotes Open Formulae -- Use only
interior points
midpoint rule

USC
Trapezoid Rule
Straight-line approximation
| | ) x ( f ) x ( f
2
h
) x ( f c ) x ( f c ) x ( f c dx ) x ( f
1 0
1 1 0 0 i
1
0 i
i
b
a
+ =
+ = ~
=
x
0
x
1

x
f(x)
L(x)
USC
Trapezoid Rule
Lagrange interpolation
0 1
0 1
0 1 1 0
0 1
( ) ( ) ( )
dx
a x , b x , , d ;
h
0
( ) (1 ) ( ) ( ) ( )
1
x x x x
L x f x f x
x x x x
x a
let h b a
b a
x a
L f a f b
x b


= +

= = = = =

= =

= +
`
= =

)
USC
Trapezoid Rule
Integrate to obtain the rule
| |
1
0
1 1
0 0
1 1
2 2
0 0
( ) ( ) ( )
( ) (1 ) ( )
( ) ( ) ( ) ( ) ( )
2 2 2
b b
a a
f x dx L x dx h L d
f a h d f b h d
h
f a h f b h f a f b


~ =
= +
= + = +
} } }
} }
USC
Example:Trapezoid Rule
Evaluate the integral
Exact solution



Trapezoidal Rule
926477 . 5216 ) 1 x 2 ( e
4
1
e
4
1
e
2
x
dx xe
1
0
x 2
4
0
x 2 x 2
4
0
x 2
= =
(

=
dx xe
4
0
x 2
}
| |
% 12 . 357
926 . 5216
66 . 23847 926 . 5216
66 . 23847 ) e 4 0 ( 2 ) 4 ( f ) 0 ( f
2
0 4
dx xe I
8
4
0
x 2
=

=
= + = +

~ =
}
c
USC
Simpsons 1/3-Rule
Approximate the function by a parabola
| | ) x ( f ) x ( f 4 ) x ( f
3
h
) x ( f c ) x ( f c ) x ( f c ) x ( f c dx ) x ( f
2 1 0
2 2 1 1 0 0 i
2
0 i
i
b
a
+ + =
+ + = ~

}
=
x
0
x
1

x
f(x)
x
2
h h
L(x)
USC
Simpsons 1/3-Rule

= =
= =
= =
=

=
+
= = =


+


+


=
1 x x
0 x x
1 x x
h
dx
d ,
h
x x
,
2
a b
h
2
b a
x , b x , a x let
) 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 (
) x ( L
2
1
0
1
1 2 0
2
1 2 0 2
1 0
1
2 1 0 1
2 0
0
2 0 1 0
2 1


) x ( f
2
) 1 (
) x ( f ) 1 ( ) x ( f
2
) 1 (
) ( L
2 1
2
0
+
+ +

USC
Simpsons 1/3-Rule
1
1
2 3
2
1
1
3
1
1
1
2 3
0
1
1
2
1
0
2
1
1
1
0
1
1
b
a
)
2

(
2
h
) f(x
)
3

( )h f(x )
2

(
2
h
) f(x
)d 1 (
2
h
) f(x )d 1 ( )h f(x
)d 1 (
2
h
) f(x d ) ( L h f(x)dx


+ +
+ =
+ + +
= ~
) f(x ) 4f(x ) f(x
3
h
f(x)dx
2 1 0
b
a
+ + =
Integrate the Lagrange interpolation
USC
Simpsons 3/8-Rule
Approximate by a cubic polynomial
| | ) x ( f ) x ( f 3 ) x ( f 3 ) x ( f
8
h 3
) f(x c ) f(x c ) f(x c ) f(x c ) x ( f c dx ) x ( f
3 2 1 0
3 3 2 2 1 1 0 0 i
3
0 i
i
b
a
+ + + =
+ + + = ~

}
=
x
0
x
1

x
f(x)
x
2
h h
L(x)
x
3
h
USC
Simpsons 3/8-Rule
) x ( f
) x x )( x x )( x x (
) x x )( x x )( x x (
) x ( f
) x x )( x x )( x x (
) x x )( x x )( x x (
) x ( f
) x x )( x x )( x x (
) x x )( x x )( x x (
) x ( f
) x x )( x x )( x x (
) x x )( x x )( x x (
) x ( L
3
2 3 1 3 0 3
2 1 0
2
3 2 1 2 0 2
3 1 0
1
3 1 2 1 0 1
3 2 0
0
3 0 2 0 1 0
3 2 1


+


+


+


=
| | ) x ( f ) x ( f 3 ) x ( f 3 ) x ( f
8
h 3
3
a - b
h ; L(x)dx f(x)dx
3 2 1 0
b
a
b
a
+ + + =
= ~
USC
Example: Simpsons Rules
Evaluate the integral
Simpsons 1/3-Rule



Simpsons 3/8-Rule
dx xe
4
0
x 2
}
| |
4
2
0
4 8
(0) 4 (2) (4)
3
2
0 4(2 ) 4 8240.411
3
5216.926 8240.411
57.96%
5216.926
x
h
I xe dx f f f
e e
c
= ~ + +
( = + + =

= =
}
| |
4
2
0
3 4 8
(0) 3 ( ) 3 ( ) (4)
8 3 3
3(4/3)
0 3(19.18922) 3(552.33933) 11923.832 6819.209
8
5216.926 6819.209
30.71%
5216.926
x
h
I xe dx f f f f
c
(
= ~ + + +
(

= + + + =

= =
}
USC
Midpoint Rule
Newton-Cotes Open Formula
) ( f
24
) a b (
)
2
b a
( f ) a b (
) x ( f ) a b ( dx ) x ( f
3
m
b
a
q
' '

+
+
=
~
a b
x
f(x)
x
m

USC
Two-point Newton-Cotes
Open Formula
Approximate by a straight line
| | ) ( f
108
) a b (
) x ( f ) x ( f
2
a b
dx ) x ( f
3
2 1
b
a
q
' '

+ +

~
}
x
0
x
1

x
f(x)
x
2
h h x
3
h
USC
Three-point Newton-Cotes Open
Formula
Approximate by a parabola
| |
) ( f
23040
) a b ( 7
) x ( f 2 ) x ( f ) x ( f 2
3
a b
dx ) x ( f
5
3 2 1
b
a
q
' ' ' '

+
+

~
}
x
0
x
1

x
f(x)
x
2
h h x
3
h h x
4

USC
Better Numerical Integration
Composite integration
Composite Trapezoidal Rule
Composite Simpsons Rule
Richardson Extrapolation
Romberg integration
USC
Apply trapezoid rule to multiple segments over
integration limits
0
1
2
3
4
5
6
7
3 5 7 9 11 13 15
Two segments
0
1
2
3
4
5
6
7
3 5 7 9 11 13 15
Four segments
0
1
2
3
4
5
6
7
3 5 7 9 11 13 15
Many segments
0
1
2
3
4
5
6
7
3 5 7 9 11 13 15
Three segments
USC
Composite Trapezoid Rule
| | | | | |
| | ) x ( f ) x ( f 2 ) 2f(x ) f(x 2 ) f(x
2
h
) f(x ) f(x
2
h
) f(x ) f(x
2
h
) f(x ) f(x
2
h
f(x)dx f(x)dx f(x)dx f(x)dx
n 1 n i 1 0
n 1 n 2 1 1 0
x
x
x
x
x
x
b
a
n
1 n
2
1
1
0
+ + + + + + =
+ + + + + + =
+ + + =

} } } }


x
0
x
1

x
f(x)
x
2
h h x
3
h h x
4

n
a b
h

=
USC
Composite Trapezoid Rule
Evaluate the integral
dx xe I
4
0
x 2
}
=
| |
| |
|
|
|
|
|
|
% 66 . 2 95 . 5355
) 4 ( f ) 75 . 3 ( f 2 ) 5 . 3 ( f 2
) 5 . 0 ( f 2 ) 25 . 0 ( f 2 ) 0 ( f
2
h
I 25 . 0 h , 16 n
% 50 . 10 76 . 5764 ) 4 ( f ) 5 . 3 ( f 2
) 3 ( f 2 ) 5 . 2 ( f 2 ) 2 ( f 2 ) 5 . 1 ( f 2
) 1 ( f 2 ) 5 . 0 ( f 2 ) 0 ( f
2
h
I 5 . 0 h , 8 n
% 71 . 39 79 . 7288 ) 4 ( f ) 3 ( f 2
) 2 ( f 2 ) 1 ( f 2 ) 0 ( f
2
h
I 1 h , 4 n
% 75 . 132 23 . 12142 ) 4 ( f ) 2 ( f 2 ) 0 ( f
2
h
I 2 h , 2 n
% 12 . 357 66 . 23847 ) 4 ( f ) 0 ( f
2
h
I 4 h , 1 n
= =
+ + +
+ + + = = =
= = + +
+ + + +
+ + = = =
= = + +
+ + = = =
= = + + = = =
= = + = = =
c
c
c
c
c

USC
Composite Trapezoid
Example
}
+
2
1
1
1
dx
x
x f(x)
1.00 0.5000
1.25 0.4444
1.50 0.4000
1.75 0.3636
2.00 0.3333
USC
Composite Trapezoid Rule with
Unequal Segments
Evaluate the integral
h
1
= 2, h
2
= 1, h
3
= 0.5, h
4
= 0.5
dx xe I
4
0
x 2
}
=
| | | |
| | | |
| | | | | |
| | % 45 . 14 58 . 5971 4 5 . 3
2
0.5

5 . 3 3e
2
0.5
3 2
2
1
2 0
2
2

) 4 ( ) 5 . 3 (
2
) 5 . 3 ( ) 3 (
2

) 3 ( ) 2 (
2
) 2 ( ) 0 (
2

) ( ) ( ) ( ) (
8 7
7 6 6 4 4
4 3
2 1
4
5 . 3
5 . 3
3
3
2
2
0
= = + +
+ + + + + =
+ + + +
+ + + =
+ + + =
} } } }
c e e
e e e e
f f
h
f f
h
f f
h
f f
h
dx x f dx x f dx x f dx x f I
USC
Composite Simpsons Rule
x
0
x
2

x
f(x)
x
4
h h x
n-2
h x
n

n
a b
h

=
...
Piecewise Quadratic approximations
h x
3
x
1
x
n-1

USC
| | | |
| |
|
| ) x ( f ) x ( f 4 ) x ( f 2
) 4f(x ) x ( f 2 ) f(x 4
) 2f(x ) f(x 4 ) 2f(x ) f(x 4 ) f(x
3
h
) f(x ) 4f(x ) f(x
3
h
) f(x ) f(x 4 ) f(x
3
h
) f(x ) f(x 4 ) f(x
3
h
f(x)dx f(x)dx f(x)dx f(x)dx
n 1 n 2 n
1 2i i 2 1 - 2i
4 3 2 1 0
n 1 n 2 n
4 3 2 2 1 0
x
x
x
x
x
x
b
a
n
2 n
4
2
2
0
+ + +
+ + + +
+ + + + + =
+ + + +
+ + + + + =
+ + + =

+

} } } }

Composite Simpsons Rule


Multiple applications of Simpsons rule
USC
Composite Simpsons Rule
Evaluate the integral
n = 2, h = 2



n = 4, h = 1
dx xe I
4
0
x 2
}
=
| |
% 70 . 8 975 . 5670
e 4 ) e 3 ( 4 ) e 2 ( 2 ) e ( 4 0
3
1
) 4 ( f ) 3 ( f 4 ) 2 ( f 2 ) 1 ( f 4 ) 0 ( f
3
h
I
8 6 4 2
= =
+ + + + =
+ + + + =
c
| |
| | % 96 . 57 411 . 8240 e 4 ) e 2 ( 4 0
3
2
) 4 ( f ) 2 ( f 4 ) 0 ( f
3
h
I
8 4
= = + + =
+ + =
c
USC
Composite Simpsons
Example
}
+
2
1
1
1
dx
x
x f(x)
1.00 0.5000
1.25 0.4444
1.50 0.4000
1.75 0.3636
2.00 0.3333
USC
Composite Simpsons Rule with
Unequal Segments
Evaluate the integral
h
1
= 1.5, h
2
= 0.5
dx xe I
4
0
x 2
}
=
| |
| |
| | | |
% 76 . 3 23 . 5413
4 ) 5 . 3 ( 4 3
3
5 . 0
3 ) 5 . 1 ( 4 0
3
5 . 1
) 4 ( 2 ) 5 . 3 ( 4 ) 3 (
3
) 3 ( 2 ) 5 . 1 ( 4 ) 0 (
3
) ( ) (
8 7 6 6 3
2
1
4
3
3
0
= =
+ + + + + =
+ + +
+ + =
+ =
} }
c
e e e e e
f f f
h
f f f
h
dx x f dx x f I
USC
Richardson Extrapolation
Use trapezoidal rule as an example
subintervals: n = 2
j
= 1, 2, 4, 8, 16, .
| |
j 2
1 j
j n 1 n 1 0
b
a
h c ) x ( f ) x ( f 2 ) f(x 2 ) f(x
2
h
f(x)dx

}

=

+ + + + + =
| |
| |
| |
| |
| | ) ( ) ( ) ( ) (
) ( ) ( ) ( ) (
) ( ) ( ) ( ) ( ) (
) ( ) ( ) (
) ( ) (
b f x f 2 x f 2 a f
2
h
I 2 j
b f x f 2 x f 2 a f
16
h
I 8 3
b f x f 2 x f 2 x f 2 a f
8
h
I 4 2
b f x f 2 a f
4
h
I 2 1
b f a f
2
h
I 1 0
Formula n j
1 n 1
j
j
j
7 1 3
3 2 1 2
1 1
0
+ + + + =
+ + + + =
+ + + + =
+ + =
+ =

USC
Richardson Extrapolation
For trapezoidal rule






k
th
level of extrapolation
(

+ + =
+ =
+ + = +
(

+ + + =
+ + =
+ + = =
}
) h ( B )
2
h
( B 16
15
1
) h ( C
)
2
h
( b )
2
h
( B A
h b ) h ( B A
h b ) h ( B h
4
c
) h ( A )
2
h
( A 4
3
1
A
)
2
h
( c )
2
h
( c )
2
h
( A A
h c h c ) h ( A A
h c ) h ( A dx ) x ( f A
4
2
4
2
4
2
4 2
4
2
2
1
4
2
2
1
2
1
b
a

1 4
) h ( C h/2) ( C 4
) h ( D
k
k

=
USC
255
I I 256
63
I I 64
15
I I 16
3
I I 4
I 16 h
I I 8 h
I I I 4 h
I I I I 2 h
I I I I I h
h O h O h O h O h O
4 k 3 k 2 k 1 k 0 k
s Boole s Simpson Trapezoid
3 j 3 1 j 2 j 2 1 j 1 j 1 1 j 0 j 0 1 j
0 4
1 3 0 3
2 2 1 2 0 2
3 1 2 1 1 1 0 1
4 0 3 0 2 0 1 0 0 0
10 8 6 4 2
, , , , , , , ,
,
, ,
, , ,
, , , ,
, , , , ,
/
/
/
/
) ( ) ( ) ( ) ( ) (
' '

= = = = =
+ + + +
3, 2, 1, k ;
1 4
I I 4
I
k
k , j k , 1 j
k
k , j
=

=
+
Romberg Integration
Accelerated Trapezoid Rule

USC
Romberg Integration
Accelerated Trapezoid Rule

926477 . 5216 dx xe I
4
0
x 2
= =
% 00050 . 0 % 00168 . 0 % 0053 . 0 % 0527 . 0 % 66 . 2
95 . 5355 25 . 0 h
68 . 5219 76 . 5764 5 . 0 h
20 . 5217 75 . 5256 79 . 7288 1 h
01 . 5217 14 . 5229 98 . 5670 2 . 12142 2 h
95 . 5216 84 . 5224 68 . 5499 41 . 8240 7 . 23847 4 h
) h ( O ) h ( O ) h ( O ) h ( O ) h ( O
4 k 3 k 2 k 1 k 0 k
s ' Boole s ' Simpson Trapezoid
10 8 6 4 2
=
=
=
=
=
=
= = = = =
c
USC
Romberg Integration
Example
}
+
2
1
1
1
dx
x
x f(x)
1.00 0.5000
1.25 0.4444
1.50 0.4000
1.75 0.3636
2.00 0.3333
USC
Gaussian Quadratures
Newton-Cotes Formulae
use evenly-spaced functional values

Gaussian Quadratures
select functional values at non-uniformly
distributed points to achieve higher accuracy
change of variables so that the interval of
integration is [-1,1]
Gauss-Legendre formulae
USC
Gaussian Quadrature on [-1, 1]
Choose (c
1
, c
2
, x
1
, x
2
) such that the method
yields exact integral for f(x) = x
0
, x
1
, x
2
, x
3

) x ( f c ) x ( f c ) x ( f c ) x ( f c dx ) x ( f
n n 2 2 1 1 i
1
1
n
1 i
i
+ + + = ~
}

=

) f(x c ) f(x c
f(x)dx : 2 n
2 2 1 1
1
1
+ =
=

x
2
x
1

-1 1
USC
Gaussian Quadrature on [-1, 1]
Exact integral for f = x
0
, x
1
, x
2
, x
3
Four equations for four unknowns
) f(x c ) f(x c f(x)dx : 2 n
2 2 1 1
1
1
+ = =

=
=
=

+ = = =
+ = = =
+ = = =
+ = = =
}
}
}
}

3
1
x
3
1
x
1 c
1 c

x c x c 0 dx x x f
x c x c
3
2
dx x x f
x c x c 0 xdx x f
c c 2 dx 1 1 f
2
1
2
1
3
2 2
3
1
1
1
1
3 3
2
2 2
2
1
1
1
1
2 2
2 2 1
1
1
1
2
1
1
1
)
3
1
( f )
3
1
( f dx ) x ( f I
1
1
+ = =
}

USC
Gaussian Quadrature on [-1, 1]
Choose (c
1
, c
2
, c
3
, x
1
, x
2
,

x
3
) such that
the method yields exact integral for
f(x) = x
0
, x
1
, x
2
, x
3
,x
4
, x
5

) x ( f c ) x ( f c ) x ( f c dx ) x ( f : 3 n
3 3 2 2 1 1
1
1
+ + = =
}

x
3
x
1

-1 1
x
2

USC
Gaussian Quadrature on [-1, 1]
5
3 3
5
2 2
5
1 1
1
1
5 5
4
3 3
4
2 2
4
1 1
1
1
4 4
3
3 3
3
2 2
3
1 1
1
1
3 3
2
3 3
2
2 2
2
1 1
1
1
2 2
3 3 2 2 1 1
1
1
3 2 1
1
1
0
5
2
0
3
2
0
2 1
x c x c x c dx x x f
x c x c x c dx x x f
x c x c x c dx x x f
x c x c x c dx x x f
x c x c x c xdx x f
c c c xdx f
+ + = = =
+ + = = =
+ + = = =
+ + = = =
+ + = = =
+ + = = =
}
}
}
}
}
}

=
=
=
=
=
=

5 / 3
0
5 / 3
9 / 5
9 / 8
9 / 5
3
2
1
3
2
1
x
x
x
c
c
c
USC
Gaussian Quadrature on [-1, 1]
Exact integral for f = x
0
, x
1
, x
2
, x
3,
x
4
, x
5
)
5
3
( f
9
5
) 0 ( f
9
8
)
5
3
( f
9
5
dx ) x ( f I
1
1
+ + = =

USC
Gaussian Quadrature on [a, b]
Coordinate transformation from [a,b] to [-1,1]
t
2
t
1
a b
} } }

=
+
+

=
1
1
1
1
b
a
dx ) x ( g dx )
2
a b
)(
2
a b
x
2
a b
( f dt ) t ( f

= =
= =
+
+

=
b t 1 x
a t 1 x
2
a b
x
2
a b
t
USC
Example: Gaussian Quadrature
Evaluate
Coordinate transformation




Two-point formula

33.34%) ( 543936 . 3477 376279 . 3468 167657324 . 9
e )
3
4
4 ( e )
3
4
4 ( )
3
1
( f )
3
1
( f dx ) x ( f I
3
4
4
3
4
4
1
1
= = + =
+ + = +

= =
+

}
c
926477 . 5216 dt te I
4
0
t 2
= =

+
= + = =
= + =
+
+

=
1
1
1
1
4 x 4
4
0
t 2
dx ) x ( f dx e ) 4 x 4 ( dt te I
2dx dt ; 2 x 2
2
a b
x
2
a b
t
USC
Example: Gaussian Quadrature
Three-point formula





Four-point formula

4.79%) ( 106689 . 4967
) 142689 . 8589 (
9
5
) 3926001 . 218 (
9
8
) 221191545 . 2 (
9
5
e ) 6 . 0 4 4 (
9
5
e ) 4 (
9
8
e ) 6 . 0 4 4 (
9
5
) 6 . 0 ( f
9
5
) 0 ( f
9
8
) 6 . 0 ( f
9
5
dx ) x ( f I
6 . 0 4 4 6 . 0 4
1
1
= =
+ + =
+ + + =
+ + = =
+

}
c
| |
| |
%) 37 . 0 ( 54375 . 5197
) 339981 . 0 ( f ) 339981 . 0 ( f 652145 . 0
) 861136 . 0 ( f ) 861136 . 0 ( f 34785 . 0 dx ) x ( f I
1
1
= =
+ +
+ = =
}

S-ar putea să vă placă și