[go: up one dir, main page]

0% found this document useful (0 votes)
19 views31 pages

Numerical Differentiation Problems

Uploaded by

Mahfuja Mim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views31 pages

Numerical Differentiation Problems

Uploaded by

Mahfuja Mim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

ME 261: Numerical Analysis

Priom Das
Lecturer
Department of Mechanical Engineering, BUET

Term: January 2023

Lecture : Numerical Differentiation Problems

ME 261: Numerical Analysis


ME 261 .. Numerical Analysis

Lecture # 02

Solution of Numerical Differentiation


ME 261 .. Numerical Differentiation

Problem #01:
a) Derive a backward difference formula for the first derivative with an
error term O(h3)
b) Use this formula to evaluate f′(x) at x = 2 for the following function
f(x) (consider step size h = 0.1):
f ( x ) = e −2 x − x
c) Compute the relative error from the analytical derivative for the
numerical result obtained in part (b).
ME 261 .. Numerical Differentiation

a) Finite difference approximations of derivatives are derived


from the approximations of Taylor’s series expansion.
i−3 i−2 i−1 i i+1 i+2 i+3
x
xi−1 f’(xi) xi xi+1 Independent variable: xi = x0 + ih,
Dependent variable: fi = f(xi) = f(x0 + ih),
h i = 0, 1, 2, ….., n

• y = f(x), yi−1 = y(xi−1) = y(x−h) = f(xi−1) = f(x−h)


• Using Taylor’s series expansion of f(xi−1) = f(x−h),
h2 h3 h 4 iv
f ( xi −1 )  f ( xi ) − hf  ( xi ) + f  ( xi ) − f  ( xi ) + f ( xi ) − O ( h 5 ) (1)
2! 3! 4!
• Similarly, using Taylor’s series expansion of f(xi−2) = f(x−2h),
( 2h ) ( 2h )
2 3

f ( xi − 2 )  f ( xi ) − ( 2h ) f  ( xi ) + f  ( xi ) − f  ( xi ) + O ( h 4 ) (2)
2! 3!
ME 261 .. Numerical Differentiation

• Similarly, using Taylor’s series expansion of f(xi−3) = f(x−3h),


( 3h ) ( 3h )
2 3

f ( xi −3 )  f ( xi ) − ( 3h ) f  ( xi ) + f  ( xi ) − f  ( xi ) + O ( h 4 ) (3)
2! 3!
• From 4×(1) − (2)
h3
4 f ( xi −1 ) − f ( xi − 2 ) = 3 f ( xi ) − 2hf  ( xi ) + 4 f  ( xi ) + O ( h 4 ) (4)
3!
• From 9×(1) − (3)
h3
9 f ( xi −1 ) − f ( xi −3 ) = 8 f ( xi ) − 6hf  ( xi ) + 18 f  ( xi ) + O ( h 4 ) (5)
3!
• From 9×(4) − 2× (5)
18 f ( xi −1 ) − 9 f ( xi − 2 ) + 2 f ( xi −3 ) = 11 f ( xi ) − 6hf  ( xi ) + O ( h 4 )
Thus, 11 f ( xi ) − 18 f ( xi −1 ) + 9 f ( xi − 2 ) − 2 f ( xi −3 )
f  ( xi ) = + O ( h3 ) Error
6h
This is called Backward Difference formula for f’(x)
ME 261 .. Numerical Differentiation

b) Now, f ( x ) = e −2 x − x
Given, xi = x = 2, h = 0.1, then f ( 2 ) = e −2( 2) − 2 = −1.982
xi−1 = x – h = 2 – 0.1 = 1.9
i i−1 i−2 i−3
xi 2 1.9 1.8 1.7
f(xi) −1.982 −1.878 −1.773 −1.667

• Backward Difference formula for f’(x) with error O(h3)


11 f ( xi ) − 18 f ( xi −1 ) + 9 f ( xi − 2 ) − 2 f ( xi −3 )
f  ( xi ) =
6h
11 f ( 2 ) − 18 f (1.9 ) + 9 f (1.8 ) − 2 f (1.7 )
f  ( 2) =
6  0.1
11( −1.982 ) − 18 ( −1.878 ) + 9 ( −1.773 ) − 2 ( −1.667 )
=
0.6
 ( 2 ) = −1.035
f num
Note: use 3 significant digits after decimals
if number has less than 4 significant digits.
ME 261 .. Numerical Differentiation

c) Now, f ( x ) = e −2 x − x
f  ( x ) = −2e −2 x − 1
 ( 2 ) = −2e
Analytical (exact) result, f exact
−2( 2 )
− 1 = −1.037
• % Relative error
 ( x ) − f num
f exact  . ( x)
Error , E = 100
 ( x)
f exact
 ( 2 ) − f num
f exact  . ( 2)
=  100
 ( 2)
f exact
−1.037 + 1.035
=  100
−1.037
= 0.193
Note: Memorize all formulae up to O(h2) for FDS and BDS, and O(h4)
for CDS.
ME 261 .. Numerical Differentiation

Problem #02: Find f ′(x) and f ″(x) of the function f(x):


f ( x ) = −0.1x 4 − 0.158 x 3 − 0.5 x 2 − 0.25 x + 12.ABC

at x = 0.5 with a step size of h = 0.25 using


a) Forward finite-divided-difference formula with an error of O(h2),
b) Backward finite-divided-difference formula with an error of O(h2),
c) Centered finite-divided-difference formula with an error of O(h4).
Find the accuracy of your results. ABC is the last three digit of your
student number. For example, if you student number is 1610123, then
ABC is 123 and the corresponding function will be
f ( x ) = −0.1x 4 − 0.158 x 3 − 0.5 x 2 − 0.25 x + 12.123
ME 261 .. Numerical Differentiation

Now, f ( x ) = −0.1x 4 − 0.158 x 3 − 0.5 x 2 − 0.25 x + 12.ABC


f  ( x ) = −0.4 x 3 − 0.158  3 x 2 − 0.5  2 x − 0.25
= −0.4 x 3 − 0.474 x 2 − x − 0.25
f  ( x ) = −0.4  3 x 2 − 0.474  2 x − 1
= −1.2 x 2 − 0.948 x − 1
Analytical (exact) result,
 ( 0.5 ) = −0.4 ( 0.5 ) − 0.474 ( 0.5 ) − ( 0.5 ) − 0.25 = −0.919
3 2
f exact

 ( 0.5 ) = −1.2 ( 0.5 ) − 0.948 ( 0.5 ) − 1 = −1.774


2
f exact

Given, xi = x = 0.5, h = 0.25, then xi−1 = x – h = 0.5 – 0.25 = 0.25


xi+1 = x + h = 0.5 + 0.25 = 0.75
Let, ABC = 000 f ( 0.5) = −0.1( 0.5) − 0.158 ( 0.5 ) − 0.5 ( 0.5) − 0.25 ( 0.5) + 12.000 = 11.724
4 3 2
ME 261 .. Numerical Differentiation

i−3 i−2 i−1 i i+1 i+2 i+3


xi −0.25 0 0.25 0.5 0.75 1.0 1.25
f(xi) 12.033 12.000 11.903 11.724 11.433 10.992 10.354
(a) Forward finite-divided-difference formula with an error of O(h2)
−3 f ( xi ) + 4 f ( xi +1 ) − f ( xi + 2 ) Relative error
f  ( xi ) =
2h  ( x ) − f num
f exact  ( x)
−3 f ( 0.5 ) + 4 f ( 0.75 ) − f (1) E=  100%
f  ( 0.5 ) =  ( x)
f exact
2 ( 0.25 )
 ( 0.5 ) − f num
f exact  ( 0.5 )
−3 (11.724 ) + 4 (11.433 ) − 10.992 =  100%
=  ( 0.5 )
f exact
0.5
 ( 0.5 ) = −0.864
f num −0.919 + 0.864
=  100%
−0.919
= 5.985%
Accuracy of the result is (100−5.985) = 94.015%
ME 261 .. Numerical Differentiation

i−3 i−2 i−1 i i+1 i+2 i+3


xi −0.25 0 0.25 0.5 0.75 1.0 1.25
f(xi) 12.033 12.000 11.903 11.724 11.433 10.992 10.354
(a) Forward finite-divided-difference formula with an error of O(h2)
2 f ( xi ) − 5 f ( xi +1 ) + 4 f ( xi + 2 ) − f ( xi +3 ) Relative error
( i)
f x =
h2  ( 0.5 ) − f num
f exact  ( 0.5 )
E=  100%
2 f ( 0.5 ) − 5 f ( 0.75 ) + 4 f (1) − f (1.25 )  ( 0.5 )
f exact
f  ( 0.5 ) =
( 0.25 ) −1.774 + 1.648
2
=  100%
−1.774
2 (11.724 ) − 5 (11.433) + 4 (10.992 ) − 10.354 = 7.103%
=
( 0.25 )
2

 ( 0.5 ) = −1.648
f num

Accuracy of the result is (100−7.103) = 92.897%


ME 261 .. Numerical Differentiation

i−3 i−2 i−1 i i+1 i+2 i+3


xi −0.25 0 0.25 0.5 0.75 1.0 1.25
f(xi) 12.033 12.000 11.903 11.724 11.433 10.992 10.354
(b) Backward finite-divided-difference formula with an error of O(h2)
3 f ( xi ) − 4 f ( xi −1 ) + f ( xi − 2 ) Relative error
f ( xi ) =
2h  ( 0.5 ) − f num
f exact  ( 0.5 )
3 f ( 0.5 ) − 4 f ( 0.25 ) + f ( 0 ) E=  100%
f  ( 0.5 ) =  ( 0.5 )
f exact
2 ( 0.25 )
−0.919 + 0.88
−3 (11.724 ) + 4 (11.903 ) − 12.000 =  100%
= −0.919
0.5 = 4.244%
 ( 0.5 ) = −0.88
f num

Accuracy of the result is (100−4.244) = 95.756%


ME 261 .. Numerical Differentiation

i−3 i−2 i−1 i i+1 i+2 i+3


xi −0.25 0 0.25 0.5 0.75 1.0 1.25
f(xi) 12.033 12.000 11.903 11.724 11.433 10.992 10.354
(b) Backward finite-divided-difference formula with an error of O(h2)
2 f ( xi ) − 5 f ( xi −1 ) + 4 f ( xi − 2 ) − f ( xi −3 ) Relative error
( i)
f x =
h2  ( 0.5 ) − f num
f exact  ( 0.5 )
E=  100%
2 f ( 0.5 ) − 5 f ( 0.25 ) + 4 f ( 0 ) − f ( −0.25 )  ( 0.5 )
f exact
f  ( 0.5 ) =
( 0.25 ) −1.774 + 1.6
2
=  100%
−1.774
2 (11.724 ) − 5 (11.903) + 4 (12.000 ) − 12.033 = 9.808%
=
( 0.25 )
2

 ( 0.5 ) = −1.6
f num

Accuracy of the result is (100−9.808) = 90.192%


ME 261 .. Numerical Differentiation

i−3 i−2 i−1 i i+1 i+2 i+3


xi −0.25 0 0.25 0.5 0.75 1.0 1.25
f(xi) 12.033 12.000 11.903 11.724 11.433 10.992 10.354
(c) Centered finite-divided-difference formula with an error of O(h4)
f (x )−8 f (x )+8 f (x )− f (x ) Relative error
f  ( xi ) = i−2 i −1 i +1 i+2

12h  ( 0.5 ) − f num


f exact  ( 0.5 )
E=  100%
f ( 0 ) − 8 f ( 0.25 ) + 8 f ( 0.75 ) − f (1) f exact ( 0.5 )

f  ( 0.5 ) =
12 ( 0.25 ) −0.919 + 0.917
=  100%
12.000 − 8 (11.903) + 8 (11.433 ) − 10.992 −0.919
= = 0.218%
3
 ( 0.5 ) = −0.917
f num

Accuracy of the result is (100−0.218) = 99.782%


ME 261 .. Numerical Differentiation

i−3 i−2 i−1 i i+1 i+2 i+3


xi −0.25 0 0.25 0.5 0.75 1.0 1.25
f(xi) 12.033 12.000 11.903 11.724 11.433 10.992 10.354
(c) Centered finite-divided-difference formula with an error of O(h4)
− f ( xi − 2 ) + 16 f ( xi −1 ) − 30 f ( xi ) + 16 f ( xi +1 ) − f ( xi + 2 )
f  ( xi ) =
12h 2
− f ( 0 ) + 16 f ( 0.25 ) − 30 f ( 0.5 ) + 16 f ( 0.75 ) − f (1)
f  ( 0.5 ) =
12 ( 0.25 )
2

−12.000 + 16 (11.903) − 30 (11.724 ) + 16 (11.433 ) − 10.992


=
0.75
 ( 0.5 ) = −1.781
f num
 ( 0.5 ) − f num
f exact  ( 0.5 ) −1.774 + 1.781
Relative error E=  100% =  100% = 0.395%
f exact ( 0.5 )
 −1.774
Accuracy of the result is (100−0.395) = 99.605%
ME 261 .. Numerical Differentiation

Problem #03: The electrical voltage drops across an inductor, according


to Faraday's law, is given by: di
VL = L
dt

where VL = voltage drop (V), L = inductance (Henry), i = current (A), t =


time (sec).
i 0 0.15 0.3 0.55 0.8 1.9
t 0 0.1 0.2 0.3 0.5 0.7

From the above data set, determine the voltage drop at the following time
steps for an inductance of 4 Henry: (a) t = 0, (b) t = 0.15, (c) t = 0.4, (d) t
= 0.7. All the results should conform to the accuracy level of O(h2).
ME 261 .. Numerical Differentiation

(a) t = 0, h = ti+1 – ti = 0.1 − 0 = 0.1, L = 4 Henry


i 0 0.15 0.3 0.55 0.8 1.9
t 0 0.1 0.2 0.3 0.5 0.7
di
Voltage drop, VL ( t = 0 ) = L
dt ti = 0

−3i ( ti ) + 4i ( ti +1 ) − i ( ti + 2 ) Using FDS with


=L
2h error of O(h2)
−3i ( 0 ) + 4i ( 0.1) − i ( 0.2 )
=4
2  0.1
−3 ( 0 ) + 4 ( 0.15 ) − ( 0.3)
=4 = 6V
0 .2
ME 261 .. Numerical Differentiation

(b) t = 0.15, h = ti+1 – ti = 0.2 − 0.15 = 0.05, L = 4 Henry


i 0 0.15 0.3 0.55 0.8 1.9
t 0 0.1 0.2 0.3 0.5 0.7
di
Voltage drop, VL ( t = 0.15 ) = L
dt ti = 0.15

i ( ti +1 ) − i ( ti −1 ) Using CDS with


=L
2h error of O(h2)
i ( 0.2 ) − i ( 0.1)
=4
2  0.05
0.3 − 0.15
=4 = 6V
0 .1
ME 261 .. Numerical Differentiation

(c) t = 0.4, h = ti+1 – ti = 0.5 − 0.4 = 0.1, L = 4 Henry


i 0 0.15 0.3 0.55 0.8 1.9
t 0 0.1 0.2 0.3 0.5 0.7
di
Voltage drop, VL ( t = 0.4 ) = L
dt ti = 0.4

i ( ti +1 ) − i ( ti −1 ) Using CDS with


=L
2h error of O(h2)
i ( 0.5 ) − i ( 0.3)
=4
2  0.1
0.8 − 0.55
=4 = 5V
0 .2
ME 261 .. Numerical Differentiation

(d) t = 0.7, h = ti – ti−1 = 0.7 − 0.5 = 0.2, L = 4 Henry


i 0 0.15 0.3 0.55 0.8 1.9
t 0 0.1 0.2 0.3 0.5 0.7
di
Voltage drop, VL ( t = 0.7 ) = L
dt ti = 0.7

3i ( ti ) − 4i ( ti −1 ) + i ( ti − 2 ) Using BDS with


=L
2h error of O(h2)
3i ( 0.7 ) − 4i ( 0.5 ) + i ( 0.3)
=4
2  0.2
3 (1.9 ) − 4 ( 0.8 ) + 0.55
=4 = 30.5V
0 .4
ME 261 .. Numerical Differentiation

Problem #04: When a fluid flows over a surface, the shear stress τ
(N/m2) at the surface is given by the following expression:
du
 =
dy surface
where viscosity, μ = 0.00024 Pa.s, u is the velocity parallel to the surface
(m/s), and y is the distance normal to the surface (m). Measurements of
the velocity of an air stream flowing above the surface are given in the
following table
y (m) 0.0 0.01 0.02 0.03 0.04
u (m/s) 0.00 45.56 70.16 90.38 100.00

Calculate the shear at the surface (y = 0) based on first-, second-, and


third-order accurate approximations.
ME 261 .. Numerical Differentiation

(a) y = 0, h = yi+1 – yi = 0.01 − 0.0 = 0.01, μ = 0.00024 Pa.s


y (m) 0.0 0.01 0.02 0.03 0.04
u (m/s) 0.00 45.56 70.16 90.38 100.00
du du
Shear stress,  ( y = 0 ) =  =
dy surface dy y =0

u ( yi +1 ) − u ( yi ) Using FDS first order


=
h approximation
u ( 0.01) − u ( 0.0 )
= 0.00024
0.01
45.56 − 0.00
= 0.00024 = 1.09344N/m 2
0.01
ME 261 .. Numerical Differentiation

(b) y = 0, h = yi+1 – yi = 0.01 − 0.0 = 0.01, μ = 0.00024 Pa.s


y (m) 0.0 0.01 0.02 0.03 0.04
u (m/s) 0.00 45.56 70.16 90.38 100.00

Shear stress,
du du
 ( y = 0) =  =
dy surface dy y =0

−3u ( yi ) + 4u ( yi +1 ) − u ( yi + 2 ) Using FDS second


=
2h order approximation
−3u ( 0.0 ) + 4u ( 0.01) − u ( 0.02 )
= 0.00024
2  0.01
−3 ( 0.00 ) + 4 ( 45.56 ) − 70.16
= 0.00024 = 1.34496N/m 2
0.02
ME 261 .. Numerical Differentiation

(c) y = 0, h = yi+1 – yi = 0.01 − 0.0 = 0.01, μ = 0.00024 Pa.s


y (m) 0.0 0.01 0.02 0.03 0.04
u (m/s) 0.00 45.56 70.16 90.38 100.00

Shear stress,
du du
 ( y = 0) =  =
dy surface
dy y =0

−11u ( yi ) + 18u ( yi +1 ) − 9u ( yi + 2 ) + 2u ( yi +3 ) Using FDS third


=
6h order approximation
−11u ( 0.0 ) + 18u ( 0.01) − 9u ( 0.02 ) + 2u ( 0.03 )
= 0.00024
6  0.01
−11( 0.00 ) + 18 ( 45.56 ) − 9 ( 70.16 ) + 2 ( 90.38 )
= 0.00024 = 1.4776N/m 2
0.06
ME 261 .. Numerical Differentiation

Problem #05: The displacement of an instrument subjected to a random


vibration test, at different instants of time, is found to be as follows:
Station, i Time, ti (s) Displacement, yi (inch)
1 0.05 0.144
2 0.10 0.172
3 0.15 0.213
4 0.20 0.296
5 0.25 0.070
6 0.30 0.085
7 0.35 0.525
8 0.40 0.110

Determine the velocity, dy/dt and acceleration, d2y/dt2 at t = 0.05, 0.10,


0.15, 0.20, 0.25, 0.30, 0.35, and 0.40 using suitable finite difference
formulae.
ME 261 .. Numerical Differentiation

h = ti+1 – ti = 0.10 − 0.05 = 0.05 Using FDS with error of O(h2)


dy −3 y ( ti ) + 4 y ( ti +1 ) − y ( ti + 2 )
Velocity, =
dt t =0.05 2h
−3 y ( 0.05 ) + 4 y ( 0.10 ) − y ( 0.15 )
=
2  0.05
−3 ( 0.144 ) + 4 ( 0.172 ) − 0.213
= = 0.43inch/s
0 .1
d2y 2 y ( ti ) − 5 y ( ti +1 ) + 4 y ( ti + 2 ) − y ( ti +3 )
Acceleration, 2 =
dt t =0.05 h2
2 y ( 0.05 ) − 5 y ( 0.10 ) + 4 y ( 0.15 ) − y ( 0.20 )
=
( 0.05)
2

2 ( 0.144 ) − 5 ( 0.172 ) + 4 ( 0.213 ) − 0.296


= = −6.4inch/s 2
( 0.05)
2
ME 261 .. Numerical Differentiation

h = ti – ti−1 = 0.40 − 0.35 = 0.05 Using BDS with error of O(h2)


dy 3 y ( ti ) − 4 y ( ti −1 ) + y ( ti − 2 )
Velocity, =
dt t =0.40 2h
3 y ( 0.40 ) − 4 y ( 0.35 ) + y ( 0.30 )
=
2  0.05
3 ( 0.110 ) − 4 ( 0.525 ) + 0.085
= = −16.85inch/s
0 .1
d2y 2 y ( ti ) − 5 y ( ti −1 ) + 4 y ( ti − 2 ) − y ( ti −3 )
Acceleration, 2 =
dt t =0.40 h2
2 y ( 0.40 ) − 5 y ( 0.35 ) + 4 y ( 0.30 ) − y ( 0.25 )
=
( 0.05)
2

2 ( 0.110 ) − 5 ( 0.525 ) + 4 ( 0.085 ) − 0.070


= = −854inch/s 2
( 0.05)
2
ME 261 .. Numerical Differentiation

h = ti+1 – ti = 0.25 − 0.20 = 0.05 Using CDS with error of O(h2)


dy y ( ti +1 ) − y ( ti −1 )
Velocity, =
dt t =0.20 2h
y ( 0.25 ) − y ( 0.15 )
=
2  0.05
0.070 − 0.213
= = −1.43inch/s
0 .1
d2y y ( ti −1 ) − 2 y ( ti ) + y ( ti +1 )
Acceleration, 2
=
dt t =0.20 h2
y ( 0.15 ) − 2 y ( 0.20 ) + y ( 0.25 )
=
( 0.05 )
2

0.213 − 2 ( 0.296 ) + 0.070


= = −123.6inch/s 2
( 0.05 )
2
ME 261 .. Numerical Differentiation

Calculated velocity, dy/dt and acceleration, d2y/dt2 using FDM of O(h2)

Displacement, Velocity, Acceleration,


Station, i Time, ti (s)
yi (inch) dy/dt (inch/s) d2y/dt2 (inch/s2)
1 0.05 0.144 0.43 −6.4
2 0.10 0.172 0.69 5.2
3 0.15 0.213 1.24 16.8
4 0.20 0.296 −1.43 −123.6
5 0.25 0.070 −2.11 96.4
6 0.30 0.085 4.55 170
7 0.35 0.525 0.25 −342
8 0.40 0.110 −16.85 −854
ME 261 .. Numerical Differentiation

Richardson’s Extrapolation Scheme


It is one of the error-correction techniques to improve the results
of numerical differentiation based on the derivative estimates
themselves. This method uses two estimates of a derivative to
compute a third, a more accurate approximation.
Say, f ( xi +1 ) − f ( xi −1 )
D = f ( x) = + O ( h2 )
2h
Using CDS, we obtain the derivative with two different h values as
D(h1) and D(h2) respectively.
We can write, D  D ( h1 ) + E ( h1 ) , D  D ( h2 ) + E ( h2 )
h12
Now, error, E ( h1 ) = f  ( xi ) = eh12
6
h22
Similarly, E ( h2 ) = f  ( xi ) = eh22
6
ME 261 .. Numerical Differentiation

Homework / Practice
Use three-point central difference formula with h = 0.1 to
approximate the second derivative of
1
f ( x) = at x = 2
x
Also use Richardson’s Extrapolation Scheme to approximate the
same derivative with O(h4) at x = 2.

You might also like