Professional Documents
Culture Documents
Ch11 PDF
Ch11 PDF
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
Numerical Integration
1
10/19/2011
Curve-Fitting
Fit a curve to the discrete data
Analytically integrate curve
Newton-Coates
Complicated function or tabulated data
Replace with approximating function that is easy to integrate
Single function OR piecewise polynomials can be used
Trapezoidal, Simpson’s rules
2
10/19/2011
Width b a H 1 f (a) H 2 f (b )
f ( a) f (b)
I (b a) 6
3
10/19/2011
Trapezoidal Rule
b f (b) f (a)
I [ f (a ) x] dx
a ba
f ( a) f (b)
I (b a)
2 7
1
Et f ( )(b a ) 3
12
or
(b a )3
Et f ( ) a< <b
12
Second derivation of the function at a
Constant point in between a and b
4
10/19/2011
y
f(x) is a 3rd order or higher
I
x1
f1 ( x)dx f 2 ( x)dx
x2
xn
f n ( x)dx
f ( x1 ) f ( x2 ) f ( x2 ) f ( x3 ) f ( xn ) f ( xn 1 )
I h h h
2 2 2
Grouping terms:
n
f ( x1 ) 2 f ( xi ) f ( xn 1 )
h n
I b a f ( x1 ) 2 f ( xi ) f ( xn 1 )
i2
2n 2
i2 10
Width
Average Height
5
10/19/2011
Simpson’s Rules
11
h f ( x1 ) 4 f ( x2 ) f ( x3 )
I f ( x1 ) 4 f ( x2 ) f ( x3 ) b
a
3 6
width
Average Height
12
6
10/19/2011
1 5 (4) (b a )5 (4)
Et h f ( ) f ( ) a< <b
90 2880
4th derivation of the function at a point in
Constant between a and b
y
f(x) is a 5th order or higher
f’’( is not constant.
f’’( is a function of 1st or higher order.
The value of f’’( changes for different
functions and different . ( a < < b)
x
7
10/19/2011
I
x1
f1 ( x)dx f 2 ( x)dx
x2
xn
f n ( 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 )
I 2h 2h 2h
6 6 6
Grouping terms
n n 1
f ( x1 ) 4 f ( xi ) 2
f ( x j ) f ( xn 1 )
h
n n 1
I b a f ( x1 ) 4 f ( xi ) 2 f ( x j ) f ( xn 1 )
i 2,4,6 j 3,5,7
3n 3 i 2,4,6 j 3,5,7
Width
Average Height
15
16
8
10/19/2011
3h f ( x1 ) 3 f ( x2 ) 3 f ( x3 ) f ( x4 )
I 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
3 5 (4) (b a )5 (4)
Et h f ( ) f ( ) 17
80 6480
Until now all formulas have been based on equally spaced data
In practice, there are many situations where this does not hold
f ( x1 ) f ( x2 ) f ( x2 ) f ( x3 ) f ( xn ) f ( xn 1 )
I h1 h2 hn
2 2 2
18
9
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 Simpson’s rule to attain19
higher accuracy
b b
Comparison of Methods I f ( x)dx f1 ( x)dx
a a
b a 3
n
f x1 2 f xi f xn 1
n
(b a ) i2
Ea
12n 3 f"
i 1
2n
f x1 4 f x2 f x3 Et
b a 5 f ( 4 )
1/3 Simpson’s (b a ) 2880
6
Rule
n n 1
f x1 4 f x 2 f x f x b a 5 n ( 4)
f
i j n 1
(b a ) i 2,4,6 j 3,5,7
Ea 4
3n 180n i 1
b a
5
3/8 Simpson’s f x1 3 f x2 3 f x3 f x4 Et f (4)
Rule (b a ) 6480
8
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
We could balance the positive and negative errors if chosen wisely
23
Constant Coefficients y
I c1 f ( x1 ) c2 f ( x2 )
• 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
1 1
I g ( x )dx (a0 a1 x a2 x 2 a3 x 3 )dx
1 1
1 1 1 1
a0 1 dx a1 x dx a2 x 2 dx a3 x 3 dx
1 1 1 1
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)=x: x1 x2
1
1
x dx c1 f ( x1 ) c2 f ( x2 ) 0 c1 x1 c2 x2
13
10/19/2011
x
• So, we found two points (x1=-0.5773503 & -1 x1 x2 +1
x2=+0.5773503) and two constants (c1=1 & c2=1)
such that they can return Exact Integral Value for y
these four functions. f(x)=x
-1 x1
x
For these four functions: x2 +1
1 y
1
f ( x ) dx c1 f ( x1 ) c2 f ( x2 ) f(x)=x2
1 1
1 f ( ) 1 f ( ) x
3 3 -1 x1 x2 +1
y
f(x)=x3
-1 x1
x
x2 +1
• Any general 3rd order function composed of the four mentioned functions (go back to
two last slide).
• So, by using 2-Point Gauss-Legendre method we can find the Exact Solution for the integral of
any 3rd function:
1 1 1
For these any 3rd (or lower) order functions: 1
f ( x) dx c1 f ( x1 ) c2 f ( x2 ) 1 f (
3
) 1 f (
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
In general form:
1
n-Point Gauss-Legendre formula:
1
f ( x ) dx c1 f ( x1 ) c2 f ( x2 ) ... cn f ( xn )
ba ba
a0 a1
2 2
x
b a b a xd dx
b a dx
d
2 2
15
10/19/2011
xd i Error:
~f 4()
~f 6()
~f 8()
~f 10()
~f 12()
In summary
Numerical Integration necessary for discrete data, complicated functions, etc.
32
16