Sie sind auf Seite 1von 10

NUMERICAL

DIFFERENTIATION
Lec. 3.1: Differentiation in Single Variable
Dr. Niket Kaisare
Department of Chemical Engineering
IIT–Madras

NPTEL Course: MATLAB Programming for Numerical Computations — Week-3

Numerical Differentiation

• From definition of ! " # :


! #+ℎ −! #
! " # = lim
(→* ℎ
! #+ℎ −! #
!" # ≈

• From Taylor’s Series:
ℎ/ "" ! #+ℎ −! #
! #+ℎ =! # + ℎ! " # + ! # ⇒ ! " # = +3 ℎ
2 ℎ
First Derivatives
• Forward Difference Formula:
! #+ℎ −! #
!" # = +3 ℎ

• Central Difference Formula:
! #+ℎ −! #−ℎ
!" # = + 3 ℎ/
2ℎ
• Backward Difference Formula:
! # −! #−ℎ
!" # = +3 ℎ

Example
tan −1 (1+10 −4 ) − tan −1 (1) ε = 5e-5
−4
10
"d −1 %
$# tan (x)'& tan −1 (1+10 −4 ) − tan −1 (1−10 −4 )
dx x=1 ε = 2e-9
2 ×10 −4

tan −1 (1) − tan −1 (1−10 −4 )


ε = 5e-5
10 −4
The Choice of ℎ in Differentiation

• Order of accuracy:
• Previous example was done for ℎ = 1067

• Repeat for a range of values, ℎ = 10 68 ,10 6/ ,⋯ , 106;

• Make a log-log plot

• Recall Module 2: Tradeoff between Truncation and Roundoff Errors

• Repeat for a range of values, ℎ = 10 68 ,10 6/ ,⋯ , 1068*

Example-2 (for Practice)

• Example from: Computational Techniques (Module-6, Part-2)


http://nptel.ac.in/courses/103106074/21
! # = 2 − # + ln #
• True solutions
1 1
!" # = − 1, ! "" # = −
# #/
End of Lecture 3.1

NUMERICAL DIFFERENTIATION
Lec. 3.2: Differentiation in Single Variable
Dr. Niket Kaisare
Department of Chemical Engineering
IIT–Madras

NPTEL Course: MATLAB Programming for Numerical Computations — Week-3


Higher Derivatives

• Second derivative (central difference)


f ( xi +1 ) − 2 f ( xi ) + f ( xi −1 )
f ʹʹ( xi ) =
h 2
+ O h2 ( )

• Third derivative (central difference)

f ( xi + 2 ) − 2 f ( xi +1 ) + 2 f ( xi −1 ) − f ( xi − 2 )
f ʹʹʹ( xi ) =
h 2
( )
+ O h2

Example-1

• Consider again: ! # = tan68 #


• True solutions
1 2#
!" # = , ! "" # = −
1 + #/ 1 + #/ /

• Solve the above using central differences to find ! " # and ! "" #
Example-2

• Example from: Computational Techniques (Module-6, Part-2)


http://nptel.ac.in/courses/103106074/21
! # = 2 − # + ln #
• True solutions
1 1
!" # = − 1, ! "" # = −
# #/
• Solve the above using central differences to find ! " # and ! "" #

Physical Example

• Consider:
6B
? = @A CD E8./;, @ = 1000, BC = 2500

• To find ? " at T = 600 using Central Difference Formula


• Choose ℎ~ I ×10 6K

• Try with other values of ℎ


8/R
• Optimal value of ℎ ∝ MNOP(
End of Lecture 3.2

NUMERICAL DIFFERENTIATION
Lec. 3.3: Partial Derivatives
Dr. Niket Kaisare
Department of Chemical Engineering
IIT–Madras

NPTEL Course: MATLAB Programming for Numerical Computations — Week-3


Physical Example

• Consider:
6B
? = @A CD E8./;, @ = 1000, BC = 2500

• To find ? " at T = 600 using Central Difference Formula


• Choose ℎ~ I ×10 6K

• Try with other values of ℎ


8/R
• Optimal value of ℎ ∝ MNOP(

A Function of Multiple Variables


• Consider the following function:
#
! S = sin #8 exp −#/ , # = #8
/
• Since f is a function of two variables:

X!
= cos #8 A 6[\
X#8
X!
= − sin #8 A 6[\
X#/
A Function of Multiple Variables
• Consider the following function:
#
! S = sin #8 exp −#/ , # = #8
/
• The partial differential (è gradient in Transport Phenomena):

X! X!
]! S = = cos #8 A 6[\ − sin #8 A 6[\
X#8 X#/

“Jacobian” for a vector-valued function ^ S


• For a _-dimensional vector S, and `-valued vector function ^ S :

X!8 X!8 X!8



X#8 X#/ X#c
!8 S
X!/ X!/ X!/
! S ⋯
^ S = / b = X#8 X#/ X#c

!N S ⋮ ⋮ ⋱ ⋮
X!N X!N X!N

X#8 X#/ X#c
Practice Problem

• For the reaction rate:


f
? = @ exp − E8./;
gI
hi hi
find b = hD hj

hi k8 ℎ k8 ℎ
• To obtain è compute r at: k + 8 and k − 8
hD / 0 / 0
hi k8 0 k8 0
• To obtain è compute r at: k + and k −
hj / ℎ/ / ℎ/

End of Lecture 3.3

Das könnte Ihnen auch gefallen