SMA 3261 - Lecture 4 - Numerical - Differentiation
SMA 3261 - Lecture 4 - Numerical - Differentiation
NUMERICAL DIFFERENTIATION
Dr. Ndung’u Reuben M.
This approach is used to differentiate;
a) a function given by a set of tabular values,
b) complicated functions.
Definition
Numerical differentiation is the process of computing the value of the derivative 𝑑𝑦⁄𝑑𝑥 for
some particular value of 𝑥 from the given data when the form of the function is not known.
It is developed by fitting approximating functions to a set of data and differentiating the
approximating function.
𝑑 𝑑
Thus, (𝑓(𝑥)) = (𝑃𝑛 (𝑥 ))
𝑑𝑥 𝑑𝑥
Procedure;
i) Fit an approximating function to the discrete data.
ii) Differentiate the function
If 𝑑𝑦⁄𝑑𝑥 is required at a point near the end of the table, we use NFDIF.
If 𝑑𝑦⁄𝑑𝑥 is required at a point near the end of the table, we use NBDIF.
If 𝑑𝑦⁄𝑑𝑥 is required at the middle of the table, a suitable central difference interpolation
formula is used.
DERIVATIVES FOR EQUALLY SPACED INTERVALS
Suppose 𝑦 = 𝑓(𝑥) is known at (𝑛 + 1) equispaced points 𝑥0 , 𝑥1 , ⋯ , 𝑥𝑛 and they are 𝑦0 , 𝑦1 , ⋯ , 𝑦𝑛
respectively, i.e. 𝑦𝑖 = 𝑓 (𝑥𝑖 ), 𝑖 = 0,1,2, ⋯ , 𝑛.
Let (𝑥𝑖 , 𝑦𝑖 ), 𝑖 = 0,1,2, ⋯ , 𝑛 be the given data points and 𝑥𝑖 = 𝑥0 + 𝑖ℎ (ℎ is the spacing).
Derivatives using Forward Difference Formula
Suppose the tabulated function is 𝑦 = 𝑓(𝑥) is replaced by NFDIF passing through the (𝑛 + 1)
points 𝑥𝑖 (𝑖 = 0,1,2, ⋯ , 𝑛).
Then NFDIF is
𝑢(𝑢 − 1) 2 𝑢(𝑢 − 1)(𝑢 − 2) 3
𝑦𝑥 = 𝑦0 + 𝑢∆𝑦0 + ∆ 𝑦0 + ∆ 𝑦0 + ⋯ (1)
2! 3!
𝑥−𝑥0 𝑑𝑢 1
where 𝑢 = , and ℎ = 𝑥𝑖+1 − 𝑥𝑖 for 𝑖 = 0,1,2, ⋯. Here 𝑢 = 𝑢(𝑥) which implies that 𝑑𝑥 = ℎ.
ℎ
DEKUT-MPS Page 1 of 10
Numerical Methods Lec. 4
Therefore,
𝑑𝑦 1 1 1 1 1
( ) = {∆𝑦0 − ∆2 𝑦0 + ∆3 𝑦0 − ∆4 𝑦0 + ∆5 𝑦0 + ⋯ } (4)
𝑑𝑥 x0 ℎ 2 3 4 5
𝑑2𝑦 1 11 5
( 2 ) = 2 {∆2 𝑦0 − ∆3 𝑦0 + ∆4 𝑦0 − ∆5 𝑦0 + ⋯ } (5)
𝑑𝑥 x h 12 6
0
and so on
Worked example
1. Find 𝑦 ′ (3) from the following data using an appropriate Newton’s difference interpolating
formula. Work with 4 decimal places.
𝑥 3 3.2 3.4 3.6 3.8 4.0
𝑦 −14 −10.032 −5.296 −0.256 6.672 14
Solution
𝑥 𝑦 ∆𝑦 ∆2 𝑦 ∆3 𝑦 ∆4 𝑦 ∆5 𝑦
3 −14
3.968
3.2 −10.032 0.768
4.736 −0.464
3.4 −5.296 0.304 2.048
5.04 1.584 −5.12
3.6 −0.2356 1.888 −3.072
6.928 −1.488
3.8 6.672 0.4
7.328
4 14
DEKUT-MPS Page 2 of 10
Numerical Methods Lec. 4
𝑠 = 0, ℎ = 0.2
1 1 1 1 1
𝑓 ′ (𝑥 ) = ∗ {∆𝑦0 − ∆2 𝑦0 + ∆3 𝑦0 − ∆4 𝑦0 + ∆5 𝑦0 }
ℎ 2 3 4 5
1 1 1 1 1
𝑓 ′(3) = ∗ {3.968 − (0.768) + (−0.464) − (2.048) + (−5.12)}
0.2 2 3 4 5
= 5 ∗ {3.968 − 0.384 − 0.1547 − 0.512 − 1.024}
= 9.4665
Exercises
1. From the following table of values, estimate 𝑦 ′(1.05) and 𝑦 ′′ (1.05):
𝑥 1.00 1.05 1.10 1.15 1.20 1.25 1.30
𝑦 1.0000 1.0247 1.0488 1.0724 1.0954 1.1180 1.1402
2. A slider in a machine moves along a fixed straight rod. Its distance 𝑥 cm along the rod is
given below for various values of time 𝑡 (seconds). Find the velocity of the slider and its
acceleration when 𝑡 = 0.1𝑠.
𝑡 0.0 0.1 0.2 0.3 0.4 0.5 0.6
𝑥 3.013 3.162 3.287 3.364 3.395 3.381 3.324
3. Using Newton’s forward interpolation formula find the value of cos 420 from the following
data.
𝑑2𝑦 1 2 3
6𝑢2 + 18𝑢 + 11 4
= {∇ 𝑦n + ( u + 1) ∇ 𝑦n + ∇ 𝑦n
𝑑𝑥 2 h2 12
2𝑢3 + 12𝑢2 + 21𝑢 + 10 5
+ ∇ 𝑦n + ⋯ } − − − − − (7)
12
DEKUT-MPS Page 3 of 10
Numerical Methods Lec. 4
𝑑𝑦 1 1 1 1 1
( ) = {∇𝑦n + ∇2 𝑦n + ∇3 𝑦n + ∇4 𝑦n + ∇5 𝑦n + ⋯ } (8)
𝑑𝑥 xn ℎ 2! 3! 4! 5!
𝑑2𝑦 1 11 4 5
( 2 ) = 2 {∇2 𝑦n + ∇3 𝑦n + ∇ 𝑦n + ∇5 𝑦n + ⋯ } (9)
𝑑𝑥 x h 12 6
n
Worked example
𝑑𝑦
1. Find the value of 𝑑𝑥 at 𝑥 = 10 from the following data, using Newton’s formula.
𝑥 2 4 6 8 10
𝑦 1.5836 1.7974 2.0442 2.3275 2.6511
Solution
𝑥 𝑦 ∇𝑦 ∇2 𝑦 ∇3 𝑦 ∇4 y
2 1.5836
4 1.7974 0.2138
6 2.0442 0.2468 0.033
8 2.3275 0.2833 0.0365 0.0035
10 2.6511 0.3236 0.0403 0.0038 0.0003
Here 𝑥𝑛 = 10, 𝑥 = 10, ℎ = 2, 𝑢 = 0. Thus,
𝑑𝑦 1 1 1 1
( ) = [∇𝑦𝑛 + ∇2 𝑦𝑛 + ∇3 𝑦𝑛 + ∇4 𝑦𝑛 ]
𝑑𝑥 𝑥=𝑥𝑛 ℎ 2 3 4
1 1 1 1
= [0.3236 + ∗ (0.0403) + ∗ (0.0038) + ∗ (0.0003)] = 0.17254583
2 2 3 4
𝑑2 𝑦
2. Find the value of 𝑑𝑥2 at 𝑥 = 9.5 from the following data, using an appropriate formula.
𝑥 2 4 6 8 10
𝑦 1.5836 1.7974 2.0442 2.3275 2.6511
Solution
𝑥 𝑦 ∇𝑦 ∇2 𝑦 ∇3 𝑦 ∇4 y
2 1.5836
4 1.7974 0.2138
6 2.0442 0.2468 0.033
8 2.3275 0.2833 0.0365 0.0035
10 2.6511 0.3236 0.0403 0.0038 0.0003
9.5−10
Here 𝑥𝑛 = 10, 𝑥 = 9.5, ℎ = 2, 𝑠 = = −0.25. Thus,
2
DEKUT-MPS Page 4 of 10
Numerical Methods Lec. 4
1 2 3
6𝑢2 + 18𝑢 + 11 4
𝑦= {∇ 𝑦𝑛 + ( 𝑠 + 1) ∇ 𝑦𝑛 + ∇ 𝑦𝑛 }
ℎ2 12
1 6(−0.25)2 + 18(−0.25) + 11
= {(0.0403) + ( −0.25 + 1)( 0.0038) + (0.0003)}
22 12
1
= {0.0403 + 0.00285 + 0.000171875}
4
= 0.01083046875
Exercises
1. Given that
If derivatives are near the middle of a difference table, it is better to use a central difference
formula.
Any of the central difference interpolation formula can be used to give a central difference
differentiation formula
Based on Stirling formula
𝑓 (𝑥 ) = 𝑝 (𝑢 )
(∆𝑓0 + ∆𝑓−1 ) 𝑢2 2 𝑢(𝑢2 − 1) (∆3 𝑓−1 + ∆3 𝑓−2 )
= 𝑓0 + 𝑢 + ∆ 𝑓−1 +
2 2! 3! 2
𝑢2 (𝑢2 − 12 ) 4 𝑢(𝑢2 − 12 )(𝑢2 − 22 ) (∆5 𝑓−2 + ∆5 𝑓−3 ) (10)
+ ∆ 𝑓−2 +
4! 5! 2
𝑢2 (𝑢2 − 12 )(𝑢2 − 22 ) 6
+ ∆ 𝑓−3 + ⋯
6!
𝑥−𝑥0 𝑑𝑢 1
Differentiating with respect to 𝑥, we get (where since 𝑢 = , ⇒ 𝑑𝑥 = ℎ)
ℎ
DEKUT-MPS Page 5 of 10
Numerical Methods Lec. 4
𝑑𝑦 𝑑𝑦 𝑑𝑢 1 (∆𝑓0 + ∆𝑓−1 ) 2
(3𝑢2 − 1) (∆3 𝑓−2 + ∆3 𝑓−1 ) (4𝑢3 − 2𝑢) 4
= · = { + 𝑢∆ 𝑓−1 + + ∆ 𝑓−2
𝑑𝑥 𝑑𝑢 𝑑𝑥 ℎ 2 3! 2 4!
(5𝑢4 − 15𝑢2 + 4) (∆5 𝑓−3 + ∆5 𝑓−2 ) (6𝑢5 − 20𝑢3 + 8) 6
+ + ∆ 𝑓−3 } − − − (11)
5! 2 6!
𝑑𝑦 𝑑𝑦 𝑑𝑢 1 (∆𝑓0 + ∆𝑓−1 )
= · = { + 𝑢∆2 𝑓−1
𝑑𝑥 𝑑𝑢 𝑑𝑥 ℎ 2
(3𝑢2 − 1) (∆3 𝑓−2 + ∆3 𝑓−1 ) (4𝑢3 − 2𝑢) 4
+ + ∆ 𝑓−2
3! 2 4!
(5𝑢4 − 15𝑢2 + 4) (∆5 𝑓−3 + ∆5 𝑓−2 ) (12)
+
5! 2
(6𝑢5 − 20𝑢3 + 8) 6
+ ∆ 𝑓−3 }
6!
𝑑2𝑦 1 2
(∆3 𝑓−2 + ∆3 𝑓−1 ) (12𝑢2 − 2) 4
= {∆ 𝑓−1 + 𝑢 + ∆ 𝑓−2
𝑑𝑥 2 ℎ2 2 4!
(20𝑢3 − 30𝑢) (∆5 𝑓−3 + ∆5 𝑓−2 ) (14)
+ + ⋯}
5! 2
𝑑2𝑦 1 1 8
( 2 ) = 2 {∆2 𝑓−1 + ∆4 𝑓−2 + ∆6 𝑓−3 + ⋯ } (15)
𝑑𝑥 𝑥 ℎ 12 6!
0
Worked example
DEKUT-MPS Page 6 of 10
Numerical Methods Lec. 4
Solution
𝑥 𝑦 ∆𝑦 ∆2 𝑦 ∆3 𝑦 ∆4 𝑦
60 28.2
10.0
75 38.2 −5.0
5.0 −2.3
90 43.2 −7.3 8.2
−2.3 5.9
105 40.9 −1.4
−3.7
120 37.2
93−90
ℎ = 15, 𝑥0 = 90, 𝑥 = 93 and 𝑦0 = 43.2, 𝑠 = = 0.2
15
By Stirling’s formula,
𝑑𝑦 1 (∆𝑦0 + ∆𝑦−1 ) 2
(3𝑠 2 − 1) (∆3 𝑦−2 + ∆3 𝑦−1 ) (4𝑠 3 − 2𝑠) 4
( ) = { + 𝑠∆ 𝑦−1 + + ∆ 𝑦−2 }
𝑑𝑥 𝑥 ℎ 2 3! 2 4!
1 (5 − 23) (3(0.2)2 − 1) (−2.3 + 5.9)
= { + (0.2)(−7.3) +
15 2 3! 2
(4(0.2)3 − 2(0.2))
+ (8.2)}
4!
1 2.7 3.168 3.0716 1
= { + (−1.46) − − }= {1.35 − 1.46 − 0.264 − 0.1257}
15 2 12 24 15
= −0.03331
Exercises
𝑑𝐼
1. The voltage 𝐸 (𝑡) in an electrical circuit obeys the equation 𝐸 (𝑡) = 𝐿 𝐷𝑡 + 𝑅𝐼 (𝑡), where 𝐿 is
the inductance and 𝑅 is the resistance. If 𝐿 = 0.05, 𝑅 = 2 and 𝐼 (𝑡) at time 𝑡 is given by the
table
2. The deflection 𝑦, measured at various distances 𝑥 from one end of a cantilever, is given by
DEKUT-MPS Page 7 of 10
Numerical Methods Lec. 4
Which is the formula for finding derivatives using Newton’s General divided difference formula.
Worked example
1. Find a polynomial satisfied by (−3,367), (−1,21), (0,7), (2, −3) and (5,1287). Use it to
evaluate 𝑓 ′(−2).
Solution
Divided difference table is
DEKUT-MPS Page 8 of 10
Numerical Methods Lec. 4
Combined Exercises
1) Using the data given in the table find (a) 𝑦 ′ (1.1), 𝑦 ′′ (1.1), (b) 𝑦 ′ (1.6) and 𝑦 ′′ (1.6):
𝑥 1.0 1.1 1.2 1.3 1.4 1.5 1.6
𝑦 7.989 8.403 8.781 9.129 9.451 9.750 10.031
2) The function 𝑦 = sin 𝑥 is tabulated in the scheme below. Find the derivatives at the points 𝑥 = 1, 𝑥 =
1.25 and 𝑥 = 0.75.
𝑥 0.7 0.8 0.9 1.0 1.1 1.2 1.3
𝑦 0.644218 0.717356 0.783327 0.841471 0.891207 0.932039 0.963558
DEKUT-MPS Page 9 of 10
Numerical Methods Lec. 4
1
3) Find 𝑓 ′ (1) for 𝑓(𝑥) = (1+𝑥 2) using the following data:
𝑥 50 51 52 53 54 55 56
1⁄6 3.6840 3.7084 3.7325 3.7563 3.7798 3.8030 3.8259
𝑦=𝑥
6) A rod is rotating in a plane. The following table gives the angle 𝜃 (radians) through which
the rod has turned for various values of the time 𝑡 second.
𝑡 0 0.2 0.4 0.6 0.8 1.0 1.2
𝜃 0 0.12 0.49 1.12 2.02 3.20 4.67
Calculate the angular velocity and the angular acceleration of the rod, when 𝑡 = 0.2 second.
DEKUT-MPS Page 10 of 10