Professional Documents
Culture Documents
Dr. Balhoff
Numerical Integration
Numerical Methods with MATLAB,
Recktenwald, Chapter 11
and
Numerical Methods for Engineers, Chapra and Canale, 5th Ed., Part Six, Chapters 21 and 22
and
Applied Numerical Methods with MATLAB, Chapra, 2nd Ed., Part Five, Chapters 17 and 18
1
Numerical Integration
10/19/2011
Curve-Fitting
Newton-Coates
10/19/2011
Width b a
I (b a)
H 1 f (a)
f ( a) f (b)
2
H 2 f (b )
6
10/19/2011
Trapezoidal Rule
I f ( x ) dx f1 ( x ) dx
f1 ( x) f (a )
Area under line is an estimate of the integral b/w the limits a and b
b
I [ f (a )
a
f (b) f (a )
x
ba
f (b) f (a)
x] dx
ba
I (b a)
f ( a) f (b)
2
Et
1
f ( )(b a ) 3
12
or
Et
(b a )3
f ( )
12
Constant
a< <b
10/19/2011
Et k f ( )
f ( ) 0
Zero for all : a < < b
x
y
f ( ) const ant
Constant for all : a < < b
x
y
x2
x1
x3
xn1
x2
xn
f1 ( x)dx f 2 ( x)dx
f n ( x)dx
f ( x2 ) f ( x3 )
f ( xn ) f ( xn 1 )
f ( x1 ) f ( x2 )
h
h
2
2
2
Grouping terms:
I h
f ( x1 ) 2 f ( xi ) f ( xn 1 )
n
h
I b a
f ( x1 ) 2 f ( xi ) f ( xn 1 )
2n
i2
2
i2
Width
10
Average Height
10/19/2011
Simpsons Rules
11
I f ( x)dx f 2 ( x)dx
f ( x1 ) 4 f ( x2 ) f ( x3 )
h
a
f ( x1 ) 4 f ( x2 ) f ( x3 ) b
3
6
width
Average
Height
12
10/19/2011
Et
1 5 (4)
(b a )5 (4)
h f ( )
f ( )
90
2880
Constant
Et m f ( 4) ( )
f ( 4 ) ( ) 0
x
y
a< <b
f ( 4 ) ( ) const ant
Constant for all : a < < b
x
y
10/19/2011
ba
n
x2
x1
xn1
x2
xn
f n ( x)dx
x3
f1 ( x)dx f 2 ( x)dx
f ( x1 ) 4 f ( x2 ) f ( x3 )
f ( x3 ) 4 f ( x4 ) f ( x5 )
f ( xn 1 ) 4 f ( xn ) f ( xn 1 )
2h
2h
6
6
6
Grouping terms
f ( x1 ) 4
f ( xi ) 2
n 1
f ( x j ) f ( xn 1 )
n
n 1
h
f ( x1 ) 4 f ( xi ) 2 f ( x j ) f ( xn 1 )
I b a
3n
3
i
2,4,6
j
3,5,7
Width
i 2,4,6
j 3,5,7
Average Height
15
16
10/19/2011
I f ( x)dx f3 ( x) dx
f ( x1 ) 3 f ( x2 ) 3 f ( x3 ) f ( x4 )
3h
f ( x1 ) 3 f ( x2 ) 3 f ( x3 ) f x4 b a
8
8
width
Average
Height
Error:
Same order accuracy as Simpson 1/3 rule so 1/3 rule is usually desired
Sometimes combine 1/3 and 3/8 rule when the segments are odd
Et
3 5 (4)
(b a )5 (4)
h f ( )
f ( )
80
6480
17
Until now all formulas have been based on equally spaced data
In practice, there are many situations where this does not hold
I h1
f ( x2 ) f ( x3 )
f ( xn ) f ( xn 1 )
f ( x1 ) f ( x2 )
h2
hn
2
2
2
18
10/19/2011
Use of the Trapezoidal rule to determine the integral of unevenly spaced data.
Notice how the shaded segments could be evaluated with Simpsons rule to attain
19
higher accuracy
Comparison of Methods
Method
I f ( x)dx f1 ( x)dx
Equation
(b a)
Trapezoid
Error
f x1 f x2
2
Et
1
3
f " b a
12
(b a )
1/3 Simpsons
Rule
(b a )
f x1 2 f xi f xn 1
3/8 Simpsons
Rule
2n
f x1 4 f x2 f x3
6
f x1 4
(b a )
Ea
i2
Et
j 3,5,7
n 1
3n
f x1 3 f x2 3 f x3 f x4
(b a )
8
2880
Ea
Et
12n
b a 5
n 1
f x 2 f x f x
i 2,4,6
b a 3
b a 5
180n
b a
6480
f"
i 1
f ( 4 )
( 4)
f
i 1
f (4)
20
10
10/19/2011
* To keep consistent notation in the above table replace x0 with x1, x1 with
x2, etc.
21
22
11
10/19/2011
Gauss Quadrature
Suppose we could evaluate the area under a straight line joining any
two points on the curve
Trapezoidal Rule
Gauss Quadrature
23
Constant Coefficients
I c1 f ( x1 ) c2 f ( x2 )
Value of the function at two indicative
points within the interval
a <x1 & x2 < b
a x1
x2 b
So, the question is what are these 4 unknowns (c1, c2, x1 & x2) such that:
b
I f ( x )dx c1 f ( x1 ) c2 f ( x2 )
a
12
10/19/2011
What special?
Want to have exact solution for any 3rd order function
Integral limits are -1 to +1
g ( x) a0 a1 x a2 x 2 a3 x 3
1
a0 1 dx a1 x dx a2 x 2 dx a3 x 3 dx
So, if the Gauss-Quadrature formula (c1x1+c2x2) can calculate exact solution for
these 4 components, it can find exact solution for the whole function.
If f(x)=1:
x2
x1
x12
0 c1 x1 c2 x2
x22
2
2
2
c1 x1 c2 x2
3
x 2 dx c1 f ( x1 ) c2 f ( x2 )
If f(x)=x3:
2 c1 1 c2 1
x dx c1 f ( x1 ) c2 f ( x2 )
If f(x)=x2:
1 dx c1 f ( x1 ) c2 f ( x2 )
If f(x)=x:
1
x13
x23
x 3 dx c1 f ( x1 ) c2 f ( x2 )
0 c1 x1 c2 x2
c1 1
x1
c2 1
1
0.5773503
3
x2
1
0.5773503
3
13
10/19/2011
y
f(x)=1
-1
x1
x2 +1
y
f(x)=x
-1 x1
x2 +1
f ( x ) dx c1 f ( x1 ) c2 f ( x2 )
1 f (
1
1
) 1 f (
)
3
3
f(x)=x2
x
x2 +1
-1 x1
y
f(x)=x3
-1 x1
x2 +1
f ( x) dx c1 f ( x1 ) c2 f ( x2 ) 1 f (
1
1
) 1 f (
)
3
3
For any higher order (4th order or higher) polynomial, or any non-polynomial function 2-Point
Gauss-Legendre method does not return the Exact Solution. It will have some errors and returns
Approximate Solution.
14
10/19/2011
Method
f ( x ) dx c1 f ( x1 ) c2 f ( x2 ) ... cn f ( xn )
3rd
2-Point Gauss-Legendre
3-Point Gauss-Legendre
4-Point Gauss-Legendre
.
n-Point Gauss-Legendre
~f(4)()
~f(6)()
~f(8)()
.
~f(2n)()
up to
order
up to 5th order
up to 7th order
.
up to (2n-1)th order
x a0 a1 xd
a a0 a1 (1)
a0
b a0 a1 (1)
ba
2
a1
ba
2
b a b a xd
2
dx
b a dx
2
15
10/19/2011
g(xd)
ba
f ( x) dx f (a0 a1 xd ) (
)dxd
1
2
1
g ( xd )dxd c1 g ( xd 1 ) c2 g ( xd 2 ) ... cn g ( xdn )
1
xd i
Error:
~f 4()
~f 6()
~f 8()
~f 10()
~f 12()
In summary
32
16