Professional Documents
Culture Documents
Numerical Integration and Differentiation
Numerical Integration and Differentiation
x x
Replacing by a Replacing by a
straight line parabola
These formulas are applicable to both closed forms (i.e., data points
at the beginning and end of the integration limits are known) and
open forms (otherwise).
These formulas are applied for equally spaced intervals.
Trapezoidal Rule
Complicated integrand function is f(x)
replaced by a first order polynomial
(straight line).
b b
I f ( x ) dx f 1 ( x ) dx
a a
f (a ) f (b )
I (b a) Trapezoidal rule
2
f(x) f(a)+f(b)
=average height
2
f(a)
I ( width ) ( average height )
f(b)
a b x
width
All the Newton-Cotes formulas can be formulated in general
form above (only definition of average height changes).
Error for trapezoidal rule: b
''
f ( x ) dx
1 '' 3 1 3
''
f
''
a
Et f ( )( b a) Ea (b a) f (b a)
12 12
Normally, we don’t have the knowledge of the true error; we can calculate the
approximate error. We need to calculate the second derivative of the function:
'' 2 3
f ( x) 400 4050 x 10800 x 8000 x
0 .8
2 3
400 4050 x 10800 x 8000 x
''
0
f 60
0 .8 0
1 3 Et and Ea have the
Ea ( 60 )( 0 . 8 ) 2 . 56
12 same order and sign
Multiple-application trapezoidal rule:
We can increase the accuracy of the integration by dividing the
interval into many segments and apply the trapezoidal rule to
each segment.
f(x)
For n+1 equally spaced base
points, there are n segments of
step size:
(b a)
h
n
x0 x1 x2 x
n 1
h
h
I f ( x0 ) 2 f ( xi ) f ( xn )
2 i 1
f ( x0 ) 2 f ( xi ) f ( xn )
i 1
I (b a)
2n
12 n
2 f i 1
related to the
n square of n !
EX: Use two-segment trapezoidal rule to integrate
2 3 4 5
f ( x) 0 .2 25 x 200 x 675 x 900 x 400 x
From a=0 to b=0.8.
0 .2 2 ( 2 . 456 ) 0 . 232
I 0 .8 1 . 0688
4
In another form:
f ( x0 ) 4 f ( x1 ) f x2 h=(b-a)/2
I (b a)
6
0 .2 4 ( 2 . 456 ) 0 . 232
I 0 .8 1 . 3675
6
5 5
(b a) (4) ( 0 .8 ) Et and Ea are equal
Ea f ( 2400 ) 0 . 273
2880 2880 because the integrand is
a fifth order polynomial
Multiple-application Simpson’s 1/3 rule
For n segments:
(b a)
h
n
Total integral can be represented
x2 x4 xn
I f ( x ) dx f ( x ) dx ... f ( x ) dx
x0 x2 xn 2
f ( x0 ) 4 f ( xi ) 2 f ( xi ) f ( xn )
i 1, 3 , 5 i 2,4,6
I (b a)
3n
5 5
(b a) (4) ( 0 .8 )
Ea 4
f 4
( 2400 ) 0 . 017067
180 ( n ) 180 ( 4 )
I f ( x ) dx f 3 ( x ) dx
a a
f ( x0 ) 3 f ( x1 ) 3 f ( x2 ) f x3
I (b a) h=(b-a)/3
8
(b a)
5 Simpson’s 3/8 rule is
(4)
Et f somewhat more
6480 accurate than 1/3 rule
f ( x0 ) f ( x1 ) f ( x1 ) f ( x2 ) f ( xn 1 ) f ( xn )
I h1 h2 .. hn
2 2 2
width of the segments (h) are not constant so the
formula cannot be written in a compact form.
I ( h1 ) E ( h1 ) I ( h2 ) E ( h2 )
(b a)
Error for multiple-equation trapezoidal rule ( n )
h
b a 2
''
E h f
12
Assuming same f ’’ for two step sizes
2
2
E ( h1 ) h 1 h1
2 or E ( h1 ) E ( h2 )
E ( h2 ) h 2 h2
Inserting the error to the previous equation, and solving for E(h2)
I ( h1 ) I ( h2 )
E ( h2 ) 2
1 h1 / h 2
Then,
1
I I ( h2 ) 2
I ( h2 ) I ( h1 )
( h1 / h 2 ) 1
It can be shown that the error for above approximation is O(h4)
although the error from use of trapezoidal rule is O(h2).
For the special case of interval being halved (h2=h1/2), we get
4 1
I I ( h2 ) I ( h1 )
3 3
O(h4) O(h2)
EX: For the numerical integration of
2 3 4 5
f ( x) 0 .2 25 x 200 x 675 x 900 x 400 x
16 1
I (1 . 623467 ) (1 . 367467 ) 1 . 640533
15 15
Algorithm:
O(h2) O(h4) O(h6) O(h8)
…
… …
…
… …
… …
…
… …
… … …
… … … …
…
Trapezoidal rule
Gauss Quadrature
In Newton-Cotes formulation, predetermined and evenly spaced
data are used. Points of integration are covered by the data.
In Gauss quadrature, points of integration are undetermined.
f(x) f(x)
a b x a b x
For the example above, integral approximation can be improved
by using two wisely chosen interior points.
Gauss quadrature offer a method to find these points.
Method of undetermined coefficients:
f(x)
Assume two points (x0, x1) so that the f(x1)
integral can be written in the form
f(x0)
I c0 f ( x0 ) c1 f ( x1 )
c‘s: constants
-1 x0 x1 1 x
This requires calculation of four unknowns.
We choose these four equations according to our preference.
We can choose a function value that is exact to third order.
1
c0 c1 2
c0 x0 c1 x1 0
2 2 2
c0 x 0
c x 1 1
3
3 3
c0 x0 c1 x 1 0
Then,
1 1 Two-point Gauss-
I f( ) f( )
3 3 Legendre formula
To change (normalize) the limits of integration, we do the
following change of variable:
x a0 a1 x d
x 0 .4 0 .4 x d dx 0 . 4 dx d
Substitute into the original equation to get:
0 .8
2 3 4 5
( 0 .2 25 x 200 x 675 x 900 x 400 x ) dx
0
1 2
0 .2 25 ( 0 . 4 0 .4 x d ) 200 ( 0 . 4 0 .4 x d )
0 . 4 dx d
3 4 5
1 675 ( 0 . 4 0 .4 x d ) 900 ( 0 . 4 0 .4 x d ) 400 ( 0 . 4 0 .4 x d )
RHS is suitable for evaluation using Gauss quadrature. Evaulating for -1/√3
(=0.516741) and for 1/√3 (=1.305837), and gives the following result:
Equivalent to third
I 0 . 516741 1 . 305837 1 . 822578 11 . 1 % order accuracy in
t Simpson’s method.
Higher-point formulas:
Higher-point versions of Gauss quadrature can be developed in the
form
I c0 f ( x0 ) c1 f ( x1 ) ... cn 1 f ( xn 1 ) n: number of points
For example, for 3 point Gauss-Legendre formulas, c’s and x’s are:
c0 0 . 5555556 x0 0 . 774596669
c1 0 . 8888889 x1 0 .0 Et ~ f(6)( )
c2 0 . 5555556 x2 0 . 774596669
2
2n 3
(n 1)!
4
(2n 2)
n= number of
Et 3
f ( ) points minus one
(2n 3) ( 2 n 2 )!
1 1
EX: Use three-point Gauss quadrature formula for the previous problem.
which is
I 0 . 2813013 0 . 8732444 0 . 4859876 1 . 640533 exact to 7 S.F.!
Numerical Differentiation
Types of Differentiation:
Forward expansion of Taylor series:
''
' f ( xi ) 2 h=step size
f ( xi 1 ) f ( xi ) f ( xi ) h h ...
2!
' f ( xi 1 ) f ( xi ) first forward
f ( xi ) O (h)
h difference
Backward expansion of Taylor series
''
' f ( xi ) 2
f ( xi 1 ) f ( xi ) f ( xi ) h h ...
2!
f ( xi ) f ( xi 1 ) first backward
'
f ( xi ) O (h) difference
h
' f ( xi 1 ) f ( xi 1 ) 2 centered
f ( xi ) O (h )
2h difference
Higher-accuracy Differentiation Formulas:
High-accuracy diffentiation formulas can be obtained by adding
more terms in Taylor expansion.
Forward Taylor series expansion:
''
' f ( xi ) 2
f ( xi 1 ) f ( xi ) f ( xi ) h h ...
2
or
''
' f ( xi 1 ) f ( xi ) f ( xi ) 2
f ( xi ) h O (h )
h 2
'' f ( xi 2
) 2 f ( xi 1 ) f ( xi )
f ( xi ) 2
h
Then,
' f ( xi 1 ) f ( xi ) f ( xi 2
) 2 f ( xi 1 ) f ( xi ) 2
f ( xi ) 2
h O (h )
h 2h
or,
' f ( xi ) 4 f ( xi 1 ) 3 f ( xi ) 2
forward
2
f ( xi ) O (h ) scheme
2h
' 3 f ( xi ) 4 f ( xi 1 ) f ( xi 2 ) 2 backward
f ( xi ) O (h ) scheme
2h
' f ( xi 2
) 8 f ( xi 1 ) 8 f ( xi 1 ) f ( xi 2 ) 4 centered
f ( xi ) O (h )
12 h scheme
EX: Calculate the approximate derivative of
4 3 2
f ( x) 0 .1 x 0 . 15 x 0 .5 x 0 . 25 x 1 .2
4 1
D D ( h2 ) D ( h1 )
3 3
at x=0.5.
4 1
D ( 0 .5 ) ( 0 . 934375 ) ( 1) 0 . 9125 t
0%
3 3
Derivatives of Unequally Spaced Data
In the previous discussion, both finite difference approximations
and Richardson extrapolation reqires evenly distributed data. So,
these methods are more suitable to evaulate functions.
Emprically derived data, experimental or from field surveys, are
usually not even.
One way is to fit a second-order Lagrange interpolating polynomial
to each set of three data points. Derivative of the polynomial:
' 2x xi xi 1
2x xi 1
xi 1
2x xi 1
xi
f ( x) f ( xi 1 ) f ( xi ) f ( xi 1 )
( xi 1
x i )( x i 1
xi 1 ) ( xi x i 1 )( x i xi 1 ) ( xi 1
x i 1 )( x i 1
xi )
Using above formula, any point in the range of three data points
can be evaluated.
This equation has the same accuracy of high-accuracy centered
difference approximation even though data is not need to be
equally spaced.
Derivatives and Integrals for Data with Error:
Differentiation process amplifies the error:
y dy/dt
x x
As a remedy, fit a smoother function (low-order polynomial) to the
uncertain data.
On the other hand, integration process reduces the error.
(Succusive negative and positive errors cancel out during
integration). No further action is required.