Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

ME 261

Numerical Analysis

Lecture-3:
Numerical Differentiation

Md. Masudur Rahman


Lecturer
Department of Mechanical Engineering
Sonargaon University
Lecture-3: Numerical Differentiation 2
Taylor’s Theorem
If the function f and its first n + 1 derivatives are continuous on an interval containing
xi and xi+1, then the value of the function at xi+1 is given by

--------(1)

Note that because the Eq. (1) is an infinite series, A remainder term is included to
account for all terms from n + 1 to infinity:

--------------------------------------(2)

where the subscript n connotes that this is the remainder for the nth-order
approximation and ξ is a value of x that lies somewhere between xi and xi+1. It is
often convenient to simplify the Taylor series by defining a step size, h = xi+1 − xi
and expressing the Eq. (1) as

------(3)

ME 261: Numerical Analysis Md. Masudur Rahman


Lecture-3: Numerical Differentiation 3
Taylor’s Theorem
where the remainder term is now

----------------------------------------------------(4)

The above equation is usually expressed as


------------------------------------------------------------(5)

where the nomenclature O(hn+1) means that the truncation error is of the order of hn+1
That is, the error is proportional to the step size h raised to the (n + l)th power.
Although this approximation implies nothing regarding the magnitude of the
derivatives that multiply hn+1, it is extremely useful in judging the comparative error
of numerical methods based on Taylor series expansions.
For example, if the error is O(h), halving the step size will halve the error. On the
other hand, if the error is O(h2), halving the step size will quarter the error.

ME 261: Numerical Analysis Md. Masudur Rahman


Lecture-3: Numerical Differentiation 4
Use of Taylor Series Expansion to Approximate a Function’s value
Use Taylor series expansions with n = 3(i.e 3rd order approximation) to approximate
f (x) = cos x at xi+1 = π/3 on the basis of the value of f (x) and its derivatives at xi = π/4.
    
Solution : Here, step size h=   , f exact ( )  cos( )  0.5
3 4 12 3 3
Now, Taylor series upto 3rd order terms
f ( xi ) 2 f ( xi ) 3
f ( xi 1 )  f ( xi )  f ( xi )h  h  h
2! 3!

Now, f ( xi )  cos( )
4
d  
f ( xi )  (cos x)   sin x ,  f ( )   sin( )
dx 4 4
d d  
f ( xi )  ( f ( x))  (  sin x)   cos x,  f ( )   cos( )
dx dx 4 4
d d  
f ( xi )  ( f ( x))  (  cos x)  sin x,  f ( )  sin( )
dx dx 4 4
 
        cos( 4 )    sin( 4 )
2 3

so, f approx ( )  cos( )    sin( )       0.4998691


3 4  12  4  12  1  2  12  1  2  3
so, Absolute Error, Ea  f exact  f approx.  0.5  0.4998691  1.309  104
f exact  f approx. 1.309  104
and Relative Rrror, E r   100%   100%   2.62  102  %
f exact 0.5
ME 261: Numerical Analysis Md. Masudur Rahman
Lecture-3: Numerical Differentiation 5
Forward Difference Approximation of the First Derivative
Taylor Series:
f ( xi ) 2 f (3) ( xi ) 3 f ( n ) ( xi ) n
f ( xi 1 )  f ( xi )  f ( xi )h  h  h  h  Rn
2! 3! n!
Now let us truncate the series after the first derivative term:
f ( xi 1 )  f ( xi )  f ( xi )h  R1
f ( xi 1 )  f ( xi ) R1
 f ( xi )                               (6)
h h
First-order Truncation
approximation error

Using Eqs. (4) and (5) yields


f ( ) 2 R f ( )
R1  h ,  1 h  O (h)
2! h 2!
Thus, if h is chosen to be sufficiently small, f ( x) can be approximated by
f ( xi 1 )  f ( xi )
f ( xi )  Forward Difference Approximation             (7)
h
f ( )
with a trancation error: Et ( h)  h  O ( h)
2!
Eq. (7) is also called forward difference quotient or, two - point formula.
The trancation error is in the order of h and can be decreased by decreasing h.
ME 261: Numerical Analysis Md. Masudur Rahman
Lecture-3: Numerical Differentiation 6
Backward Difference Approximation of the First Derivative
Taylor series can be expanded backward to calculate a previous value on the basis of a present
value, as follows
f ( xi ) 2 f (3) ( xi ) 3 n f
(n)
( xi ) n
f ( xi 1 )  f ( xi )  f ( xi )h  h  h          (1) h  Rn
2! 3! n!
Now let us truncate the series after the first derivative term:
f ( xi 1 )  f ( xi )  f ( xi )h  R1
f ( xi )  f ( xi 1 ) R1
 f ( xi )                                 (8)
h h
First-order Truncation
approximation error

f ( ) 2 R f ( )
Similarly, R1  h ,  1 h  O ( h)
2! h 2!
Thus, if h is chosen to be sufficiently small, f ( x) can be approximated by
f ( xi )  f ( xi 1 )
f ( xi )  Backward Difference Approximation             (9)
h
f ( )
with a trancation error: Et (h)  h  O ( h)
2!
Eq. (9) is also called Backward difference quotient or, two - point formula.
The trancation error is also in the order of h and can be decreased by decreasing h.
ME 261: Numerical Analysis Md. Masudur Rahman
Lecture-3: Numerical Differentiation 7
Central Difference Approximation of the First Derivative
Forward expansion of Taylor series:
f ( xi ) 2 f (3) ( xi ) 3
f ( xi 1 )  f ( xi )  f ( xi )h  h  h  ......................................(10)
2! 3!
Backward expansion of Taylor series:
f ( xi ) 2 f (3) ( xi ) 3
f ( xi 1 )  f ( xi )  f ( xi )h  h  h  .......................................(11)
2! 3!
Now, subtracting Eq. (11) from Eq. (10) we get,
2 f (3) ( xi ) 3
f ( xi 1 )  f ( xi 1 )  2 f ( xi )h  h 
3!
f ( xi 1 )  f ( xi 1 ) f (3) ( xi ) 2
 f ( xi )   h      ........................................................(12)
2h 3!
f ( xi 1 )  f ( xi 1 )
 f ( xi )   O(h 2 ) Central Difference Approximation ...............(13)
2h
Eq. (13) is also called Central difference quotient or, two - point formula.
Notice that the truncation error is of the order of h 2 in contrast to the forward and
backward approximations that were of the order of h. Consequently, the Taylor series
analysis yields the practical information that the centered difference is a more accurate
representation of the derivative.

ME 261: Numerical Analysis Md. Masudur Rahman


Lecture-3: Numerical Differentiation 8
Example-1
Use forward and backward difference approximations of O(h) and a centered
difference approximation of O(h2) to estimate the first derivative of the following
function at x = 0.5 using a step size h = 0.5.
f ( x)  0.1x 4  0.15 x 3  0.5 x 2  0.25 x  1.2

ME 261: Numerical Analysis Md. Masudur Rahman


Lecture-3: Numerical Differentiation 9
Example-1

ME 261: Numerical Analysis Md. Masudur Rahman

You might also like