Ch-7, Math-5 Lecture Note
Ch-7, Math-5 Lecture Note
Ch-7, Math-5 Lecture Note
7.1 Introduction
Numerical differentiation is the process of finding derivatives numerically for a function
whose values are given in data form generated from an experiment. For evenly distributed
data points and if we need the derivative at data points, we may use the derivative
formulas called finite differences. When the data points are not even or required
derivatives are at points other than data points, we may use interpolating polynomials.
Numerical differentiation formulas can be derived by using the Taylor series expansion or
by differentiating the interpolating polynomials. Here we shall consider both way of
deriving the derivative formulas.
Lec 6 - 1
Spring 2023-2024
E =−¿ ¿
From the expansion of f ( x 0−h) , we have 2-point backward difference formula,
f ( x 0 )−f ( x 0 −h )
f ' ( x 0 )= +E
h
h '' h2 '' '
E= f ( x 0 )− f ( x0 )+ ¿ ⋅⋅¿ ¿
with error term 2! 3!
In the two-point formula the error series is of the form
E=a1 h+a 2 h2 +a 3 h3 +⋅⋅⋅¿ ¿
where a’s does not depend on h.
By subtraction, we obtain,
2 3 '' ' 2
f ( x 0 +h )−f ( x 0−h)=2hf ( x0 )+ h f ( x0 )+ h5 f ( v ) ( x 0 )+⋅⋅⋅¿ ¿
3! 5!
'
This leads to the 3-point central formula for approximating
f ( x0 )
f ( x 0 +h )−f ( x 0−h)
f ' ( x 0 )= +E
2h
With
E =−¿ ¿
Adding the Taylor series for f ( x 0 +h ) and f ( x 0−h) , we get
2 4 ( 4)
f ( x 0 +h )+f ( x 0 −h )=2 f (x 0 )+h 2 f ( x0 )+
''
h f ( x0 )+⋅⋅⋅¿ ¿
4!
''
When this is rearranged, we get 3-point central difference formula for f ( x 0 )
f ( x 0 + h)−2 f ( x 0 )+f ( x 0 −h )
f ' ' ( x 0 )= +E
h2
Lec 6 - 2
Spring 2023-2024
Second Derivatives
1
''
f ( x 0 )≈
h2
[ f −1−2 f 0 + f 1 ] Ο(h 2 ) 3-point central difference
,
1
f ( x 0 )≈ 2 [ f 0 −2 f 1 + f 2 ]
''
Lec 6 - 3
Spring 2023-2024
Lower order formula and Richardson extrapolation can be used to deduce the higher order
'
formula. For convenience we have used the notation f ( x 0 ,h ) to clearly indicate the
approximation of f ( x 0 ) with step size h and f ( x 0 +rh )=f r .
'
Thus the 3-point central difference formula for first derivative will be written as
f −f
f ' ( x 0 ,h )= 1 −1
2h
Example 7.1 The values of distance at various times are given below
Time (t) 4 6 8 10 12
Distance(s) 7.38 12.07 18.37 26.42 36.40
2
ds
v= dt
a= d s2
The speed and acceleration can be calculated by and acceleration dt .
(a) Using three-point central difference formula estimate the speeds at (i) t=8 ,
(ii) t=7 , and (iii) t=9 .
(b) Using two-point formulas and extrapolation estimate the speeds at (i) t=4, and (ii)
t=12.
(c) Use three points central difference formula and extrapolation to estimate speed at
t=8 .
(d) Use three points central or forward or backward formula to estimate the
accelerations at (i) t=8 , (ii) t=4, and (iii) t=12.
(e) Write down MATLAB code to estimate the speed and acceleration at time t=8
using three-point central difference formulas.
(f) Use MATAB functions “sp=spline(x,y)”, “fnder(sp, dorder)” and “fnval(sp, xo)”
to estimate the speed and acceleration at time t=6.5∧10.4.
Solution
(a) Three-point central derivative formula for first derivative is
1
'
f ( x 0 , h )=
2h
[ f ( x 0+ h )−f ( x 0−h ) ]
(i) Speed at t=8
1 1
v ( 8 , 2 )=
2 ×2
[ s ( 10 ) −s ( 6 ) ] = [26.42−12.07]=3.5875 .
2
Lec 6 - 4
Spring 2023-2024
8−6
(ii) Speed at t=7 . Here h= =1 .
2
1 1
v ( 7 , 1 )=
2 ×1
[ s ( 8 ) −s (6 ) ] = [18.37−12.07]=3.15 .
4
10−8
(iii) Speed at t=9 . Here h= =1.
2
1 1
v ( 9 , 1 )=
2 ×1
[ s ( 10 )−s ( 8 ) ] = [26.42−18.37 ]=4.025 .
2
(b)
(i) For t=4, we must use forward difference formula
' 1
f ' (x 0)≈ f ( x 0 ,h )= [f ( x 0 +h ) −f ( x 0 ) ].
h
Speed at t=4 we need to use h=2∧h=4 .
1 1
v ( 4 , 2 )=
2
[ s ( 6 )−s ( 4 ) ] = [ 12.07−7.38 ]=2.345 .
2
1 1
v ( 4 , 4 )=
4
[ s ( 8 )−s ( 4 ) ] = [ 18.37−7.38 ] =2.7475 .
4
Extrapolated value is
v ( 8 , 2 )−v (8 , 4)
v R ( 4 )=v ( 8 ,2 ) + =2.345+ ( 2.345−2.7475 ) =2.9425 .
2 1−1
(ii) For t=12, we have to use backward difference formula
1
'
f ' (x 0)≈ f ( x 0 ,h )=
h
[ f ( x 0 )−f ( x 0−h ) ] .
Speed at t=12 we need to use h=2∧h=4 .
1 1
v ( 12 , 2 )=
2
[ s (12)−s ( 10 ) ] = [ 36.40−26.42 ] =4.99 .
2
1 1
v ( 12 , 4 )=
4
[ s ( 12 )−s ( 8 ) ] = [ 36.42−18.37 ] =4.5075 .
4
Extrapolated value is
v (12 , 2 )−v (12 , 4)
v R ( 12 )=v ( 12 , 2 ) + =4.99+ ( 4.99−4.5075 ) =5.4725 .
21−1
Lec 6 - 5
Spring 2023-2024
1 1
v ( 8 , 4 )=
2 ×4
[ s ( 12 )−s ( 4 ) ] = [ 36.40−7.38 ]=3.6275 .
8
Extrapolated value is
v ( 8 , 2 )−v (8 , 4 ) 3.5875−3.6275
v R ( 8 )=v ( 8 , 2 )+ 2
=3.5875+ =3.5742 .
2 −1 3
(d)
(i) For t=8 , we have to use central difference formula (it gives better approximation).
Three-point central derivative formula for second derivative is
1
2( ( 0
f ' ' (x 0 ,h)= f x +h )−2 f ( x 0 ) + f ( x 0−h ) ) .
h
Acceleration at t=8 is
1
a ( 8 , 2 )= 2
[ s ( 10 )−2 s ( 8 ) + s(6)]= 14 [26.42−2 ( 18.37 )+12.07 ]=0.4375 .
2
(ii) For ¿ 4 , three-point forward difference formula for second derivative is
1
2 ( ( 0)
f ' ' (x 0 ,h)= f x −2 f ( x 0+ h ) + f ( x 0+ 2h ) ) .
h
Acceleration at t=4 is
1
a ( 4 , 2 )= 2
[ s ( 4 )−2 s ( 6 ) +s (8)]= 14 [7.38−2 ( 12.07 ) +18.37]=0.4025 .
2
(iii) For ¿ 12, three-point backward difference formula for second derivative is
1
2 ( ( 0)
f ' ' (x 0 ,h)= f x −2 f ( x 0−h ) + f ( x 0−2 h ) ) .
h
Acceleration at t=12 is
1
a ( 12 , 2 )= 2
[ s (12 )−2 s ( 10 )+ s (8)]= 14 [36.40−2 ( 26.42 )+18.37 ]=0.4825 .
2
(d)
>> clear
>> x=[6 8 10];
>> y=[12.07 18.37 26.42];
>> h=x(2)-x(1);
>> D1=(y(3)-y(1))/(2*h);
>> D2=(y(3)-2*y(2)+y(1))/h^2;
Lec 6 - 6
Spring 2023-2024
ValD1 =
3.7501 4.9860
ValD2 =
0.4445 0.5063
Lec 6 - 7
Spring 2023-2024
Exercise 7
Numerical Differentiation
1. The distance s of a runner from a fixed point is measured (in metres) at intervals of
half a second. The data obtained is
Time t (s) 0 0.5 1 1.5 2
Distance s (m) 0 3.65 6.8 9.9 12.15
(a) Use two points difference formulas to approximate the runner’s speed at times
t = 0s and t = 2s.
(b) Use three points central difference formula to approximate the runner’s speed at
times t = 0.5s and t = 1.25s.
(c) Use three points central difference formula to approximate the runner’s
acceleration at times t = 1 s.
(d) Write down MATLAB code to estimate the speed and acceleration at time at time
t=1.5 s using three point central difference formulas.
di
(1 .2 )
(a) Find dt using three point central difference formula and extrapolation to
compute E(1.2)
(b) Compare your result with the exact solution I (t )=10 exp(−t /10)sin 2t .
(c) Use MATAB to estimate I ' (t) at each value of t using spline interpolation.
Write down the MATLAB commands to find the corresponding voltage E(t).
Lec 6 - 8
Spring 2023-2024
t (s) 8 9 10 11 12
s(t) (m) 17.453 21.460 25.752 30.302 35.084
2
ds d s
The speed and acceleration can be calculated by v= and acceleration a= 2 .
dt dt
(a) Using three-point central difference formula estimate the speeds at (i) t=9 , and
(ii) t=10.5.
(b) Using two-point formulas estimate the speeds at (i) t=8 , and (ii) t=12.
(c) Use three points central difference formula and extrapolation to estimate speed at
t=10.
(d) Use three points central or forward or backward difference formula to estimate the
accelerations at (i) t=10, (ii) t=8 and (iii) t=12.
(e) Use MATAB to estimate the speed and acceleration at time t¿ 8.5 , 10.5 ,∧11.2
using spline interpolation.
6. A rod is rotating in a plane. The follow table gives the angle θ ( in radians) through
which the rod has turned for various values of time t .
Time t (s) 0 0.2 0.4 0.6 0.8
Angle θ 0 0.12 0.49 1.12 2.02
(a) Use two points difference formula to approximate the angular velocity of the rod at
t = 0.6s.
(b) Use three points central difference formula to approximate the angular velocity of
the rod at t = 0.6s.
(c) Use three points central difference formula to approximate the angular acceleration
of the rod at t = 0.6s.
(d) Write down MATLAB code to estimate the speed and acceleration at time t=0.5 s
using three-point central difference formulas.
Lec 6 - 9
Spring 2023-2024
7. The table below gives the results of an observation, θ is the observed temperature in
degree celsius of a vessel of cooling water, t is the time in minutes from the
beginning of observation.
Time t (min) 1 3 5 7 9
temperature θ 85.3 74.5 67. 60.5 54.3
0
(a) Use two points difference formula to approximate the rate of cooling at t=3 and
t=5
(b) Use three points central difference formula to approximate the rate of cooling at
t=3 and t=4
(c) Write down MATLAB code to estimate the approximate rate of cooling at t=3 and
t=4 three-point central difference formulas.
Lec 6 - 10