Uploaded by ETAFA ABERA

NUMERICAL DIFFERENTIATION AND INTEGRATIONpd

advertisement
Numerical Differentiation And Integration For 3rd Year Students of Dambi
Dollo University,2012E.c
NUMERICAL DIFFERENTIATION AND INTEGRATION
1 NUMERICAL DIFFERENTIATION
Numerical differentiation is used to determine one of the derivatives of a given function of the
form y= f(x) at the point x= xk.
The derivative of a function at x is defined as
(
f'(x) =
)
( )
To be able to find a derivative numerically, one could make
f’(x) 
(
)
finite to give,
( )
Knowing the value of x at which you want to find the derivative of f x, we choose a value of
x to find the value of f x. To estimate the value of f x, three such approximations are
Suggested : Forward Divided Difference, Backward Divided Difference and Central Difference
Approximation.
Continuous Function
a. Forward Difference Approximation of the First Derivative
From differential calculus, we know
(
f’(x) 
)
( )
For a finite,
f’(x) 
(
)
( )
The above is the forward divided difference approximation of the first derivative. It is called
forward because you are taking a point ahead of x. To find the value of f’(x) at x= x i, we may choose
another point ahead at x=xi+1. This gives
f’( ) 
(
(
f’(x)=
(
))
( )
)
( )
1
, since
Numerical Differentiation And Integration For 3rd Year Students of Dambi
Dollo University,2012E.c
Graphical representation of forward difference approximation of first derivative
Backward Difference Approximation of the First Derivative
We know
(
f’(x) 
)
( )
For a finite,
f’(x) 
If is
(
)
( )
chosen as a negative number,
(
)
( )
( )
)
( )
(
)
f’(x) 
=
This is a backward difference approximation as you are taking a point backward from x. To find
the value of f xat x xi , we may choose another point x behind as x=xi-1 . This gives
f’(x)=
( )
(
2
(
)
,
Numerical Differentiation And Integration For 3rd Year Students of Dambi
Dollo University,2012E.c
Graphical representation of backward difference approximation of first derivative .
Forward Difference Approximation from Taylor Series
Taylor’s theorem says that if you know the value of a function f (x) at a point xi and all its
derivatives at that point, provided the derivatives are continuous between xi and xi+1 , then
f ( xi1 )  f ( xi )  f ( xi )( xi1  xi ) 
f ( xi1 )  f ( xi )  f ( xi )(x) 
1
f ( xi )( xi1  xi ) 2  ...
2!
1
f ( xi )(x) 2  ...
2!
f ( xi1 )  f ( xi ) 1
 f ( xi )(x)  ...
x
2!
f ( xi1 )  f ( xi )
f ( xi ) 
 O(x)
x
f ( xi ) 
The term O(x) shows that the error in the approximation is of the order of x . As you can see,
both forward and backward divided difference approximations of the first derivative are accurate
on the order of O(x). To get a better approximation of the first derivative, we employ another
method called central difference approximation of the first derivative.
From the Taylor series
f ( xi1 )  f ( xi )  f ( xi )(x) 
1
1
f ( xi )(x) 2  f ''' ( xi )(x) 3 ...(1)
2!
3!
and
1
1
f ( xi )(x) 2  f ''' ( xi )(x) 3 ...( 2)
2!
3!
Subtracting Equation (2) from Equation (1)
2
f ( xi1 )  f ( x x1 )  f ( xi )(2x)  f ''' ( xi )(x) 3  ...
3!
f ( xi1 )  f ( xi 1 ) 1 '''
f ( xi ) 
 f ( xi )(x) 2  ...
2x
3!
f ( xi1 )  f ( xi 1 )
f ( xi ) 
 O(x) 2
2x
f ( xi1 )  f ( xi )  f ( xi )(x) 
Hence, showing that we have obtained a more accurate formula as the error is of the order of
O(x)2.
3
Numerical Differentiation And Integration For 3rd Year Students of Dambi
Dollo University,2012E.c
Graphical representation of central difference approximation of first derivative.
Example 1:
The velocity of a rocket is given by:
V (t)= 2000
*
+-9.8t, 0 ≤ t ≤ 30.
Where: V is given in m/s and t is given in seconds. At t=16s, and a step size oft=2s .
b. Use the forward and backward difference approximation of the first derivative of V(t) to
calculate the acceleration.
c. Find the exact value of the acceleration of the rocket.
d. Find the absolute relative true error for both the forward and backward approximations.
SOLUTION
Forward difference method
a(t)=
(
)
( )
but ti=16s, t=2s ,
a(16)=
V (18) = 2000
*
(
)
(
)
(

)
(
)
+-9.8(18),
=453.02 m/s
V (16) = 2000
*
+-9.8(16),
=392.07m/s
a(16)=
(
)
(
)
=
4
=30.474m/s2
Numerical Differentiation And Integration For 3rd Year Students of Dambi
Dollo University,2012E.c
Backward difference method
a(t)
( )
(
)
,

but ti=16s, t=2s ,
a(16)=
(
)
(
)
*
V (16 = 2000
(
+-9.8(16),
)
=392.07 m/s
*
V (14) = 2000
(
+-9.8(14),
)
=334.24m/s
(
a(16)=
)
(
)
=28.915m/s2
)=
b. The exact value of a (16) can be calculated by differentiating
V (t)= 2000
+-9.8t, 0 ≤ t ≤ 30.
*
As
and
=
( )
Knowing that , a(t)=
(
)
a(t)= 2000(
[
])
-9.8,
)(
=2000(
)*
(
)
+(
=
(
a(16)=
(
)
)
=29.674m/s2
c. The absolute relative true error is:
Forward: | |
|
|
| |
|
|
=2.6967%
Backward:
5
) - 9.8,
Numerical Differentiation And Integration For 3rd Year Students of Dambi
Dollo University,2012E.c
| |
|
|
Example 2:
Repeat example 1 for the central difference approximation of the first derivative.
V (t i 1 )  V (t i  1)
2t
but ti=16s, t=2s ,
a (t i ) 


a (16) 
V (18) = 2000
*
(
)
(
)
V (18)  V (14)
2( 2)
+-9.8(18),
=453.02 m/s
V (14) = 2000
*
+-9.8(14),
=334.24m/s
453.02  334.24
= 29.694m/s2
2(2)
(b) The exact value of the acceleration at from Example 1 is s t=16s
a(16) 
a(16) =29 .674m/s2
The absolute relative true error for the answer in part (a) is
| |
|
|
From the results in example 1 (forward and backward) and example 2 (central difference), it is
clearly shown that the relative approximate error for the central difference approximation is very
small, showing that it gives more accurate result. This is because the order of accuracy is
proportional to the square of the step size.
Finite Difference Approximation of Higher Derivatives
One can also use the Taylor series to approximate a higher order derivative. For example, to
approximate f''(x) , the Taylor series is
6
Numerical Differentiation And Integration For 3rd Year Students of Dambi
Dollo University,2012E.c
f ( xi  2 )  f ( xi )  f ( xi )(2x) 
1
1
f ( xi )(2x) 2  f ''' ( xi )(2x) 3 ...(3)
2!
3!
where, x i  2  xi  2x
f ( xi 1 )  f ( xi )  f ( xi )(x) 
1
1
f ( xi )(x) 2  f ''' ( xi )(x) 3 ...( 4)
2!
3!
where, x i-1  xi  x
subtracting 2 times Equation (4) from Equation (3) gives
f ( xi  2 )  2 f ( xi 1 )   f ( xi )  f ( xi )(x) 2  f ''' ( xi )(x) 3  ...
f ( xi  2 )  2 f ( xi 1 )  f ( xi )
 f ''' ( xi )(x)  ....
2
( x)
f ( xi  2 )  2 f ( xi 1 )  f ( xi )
f ' ' ( xi ) 
 O( x)
( x) 2
f ' ' ( xi ) 
2. NUMERICAL INTEGRATION
Integration is the process of measuring the area under a function plotted on a graph. A wide
variety of numerical methods have been developed to simplify an integral. We will discuss four
well-known methods: the trapezoidal rule, Simpson’s 1/3rd Rule, Gauss Quadrature Rule, and
Romberg Integration.
Integrating discrete functions
Sometimes, the function to be integrated is given at discrete data points, and the area under the
curve is needed to be approximated. Here, we will discuss the integration of such discrete
functions,
∫
( )
Where:
 f(x)- is called the integrand and is given at discrete value of x ,
 a- lower limit of integration
 b -upper limit of integration
Multiple methods of integrating discrete functions are discussed below.
2.1 Rectangular Rule
Approximate the integration, ∫
( )
that is the area under the curve by a series of rectangles
as shown below. The base of each of these rectangles is x=(b-a)/n and its height can be
expressed as f(xi*) where xi* is the midpoint of each rectangle and n is number of rectangle.
b
 f ( x)dx  f ( x *)x  f ( x *)x  .. f ( x *)x
a
1
2
n
 x[ f ( x1*)  f ( x2 *)  .. f ( xn *)]
7
Numerical Differentiation And Integration For 3rd Year Students of Dambi
Dollo University,2012E.c
2.2 Trapezoidal Rule
The rectangular rule can be made more accurate by using trapezoids to replace the rectangles as
shown. A linear approximation of the function locally sometimes works much better than using
the averaged value like the rectangular rule does.
b
x
x
x
 f ( x)dx  2 [ f (a )  f ( x )]  2 [ f ( x )  f ( x )]  ..  2 [ f ( x )  f (b)]
a
1
1
1
1
 x[ f (a )  f ( x1 )  .. f ( xn 1 )  f (b)]
2
2
8
2
n 1
Numerical Differentiation And Integration For 3rd Year Students of Dambi
Dollo University,2012E.c
2.3 Simpson’s Rule
Still, the more accurate integration formula can be achieved by approximating the local curve by
a higher order function, such as a quadratic polynomial.
This leads to the Simpson’s rule and the formula is given
x
b
 f ( x)dx  3 [ f (a )  4 f ( x )  2 f ( x )  4 f ( x )  ..
1
a
2
3
..2 f ( x2 m2 )  4 f ( x2 m1 )  f (b)]
It is to be noted that the total number of subdivisions has to be an even number in order for the
Simpson’s formula to work properly.
Example 5
Integrate f ( x )  x 3 between x  1 and x  2.
2
1 4 2 1 4 4
3
1 x dx= 4 x |1  4 (2  1 )  3.75
Using 4 subdivisions for the numerical integration: x=
2-1
 0.25
4
Rectangular rule:
2
 x dx
3
1
 x[ f (1.125)  f (1.375)  f (1.625)  f (1.875)]
 0.25(14.9)  3.725
Trapezoidal Rule
2
 x dx
3
1
1
1
f (1)  f (1.25)  f (1.5)  f (1.75) 
f (2)]
2
2
 0.25(15.19)  3.80
 x[
9
Numerical Differentiation And Integration For 3rd Year Students of Dambi
Dollo University,2012E.c
Simpson’s Rule
2
x
 x dx  3 [ f (1)  4 f (1.25)  2 f (1.5)  4 f (1.75)  f (2)]
3
1

0.25
(45)  3.75  perfect estimation
3
10
Download