0% found this document useful (0 votes)
45 views10 pages

12 Lec6

The document discusses finite difference methods for approximating derivatives from discrete data points. It begins by using Taylor series expansions to derive forward, backward, and central difference approximations for the first and second derivatives of functions of one variable. These approximations are first and second order accurate. It then extends these methods to mixed partial derivatives of functions of two variables, using a Taylor series approach. The goal is to express derivatives as finite difference quotients so that digital solutions can be obtained for partial differential equations.
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)
45 views10 pages

12 Lec6

The document discusses finite difference methods for approximating derivatives from discrete data points. It begins by using Taylor series expansions to derive forward, backward, and central difference approximations for the first and second derivatives of functions of one variable. These approximations are first and second order accurate. It then extends these methods to mixed partial derivatives of functions of two variables, using a Taylor series approach. The goal is to express derivatives as finite difference quotients so that digital solutions can be obtained for partial differential equations.
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/ 10

Computational Fluid Dynamics for Incompressible Flows

Professor. Amaresh Dalal


Department of Mechanical Engineering
Indian Institute of Technology, Guwahati

Module 3: Finite Difference Method

Lecture 1

Finite Difference by Taylor Series Expansion

Hello everyone, so today we will start module 3, finite difference method and in today's
lecture we will learn, finite difference by Taylor Series Expansion. In last lecture, we have
learned the classifications of partial differential equations and you have seen that in heat
transfer and fluid mechanics problems there appears first derivative and second derivative of
dependent variables.

The differential of dependent variables appearing in the partial differential equation must be
expressed as approximate expression, so that a digital computer can be employed to obtain a
solution.

(Refer Slide Time: 1:27)


There are many ways to discretize the partial derivatives, but in today's lecture will use
Taylor series expansion. So, let us consider any continuous function f(x). We need to find its
first and second derivative using this finite difference approximation. For that we have to
divide the domains into discrete points or grids. Generally we use index i in x direction, and j
in y direction and k in z direction. These grid points may be both uniformly or non uniformly
distributed. Unless otherwise stated we will be using uniform spacing in our derivations.

Using Taylor series expansion we can write the first derivative as:

(∆𝑥) 𝜕𝑓 (∆𝑥)2 𝜕 2 𝑓 (∆𝑥)3 𝜕 3 𝑓


𝑓(𝑥 + ∆𝑥) = 𝑓(𝑥) + + + +⋯
1! 𝜕𝑥 2! 𝜕𝑥 2 3! 𝜕𝑥 3
𝜕𝑓 𝑓(𝑥 + ∆𝑥) − 𝑓(𝑥)
= + 𝑇𝐸
𝜕𝑥 ∆𝑥

Where, TE is the truncation error (difference between partial derivative and the finite
difference approximation) and is given by:

(∆𝑥)2 𝜕 2 𝑓 (∆𝑥)3 𝜕 3 𝑓
𝑇𝐸 = − − +⋯
2! 𝜕𝑥 2 3! 𝜕𝑥 3

This approximation is known as forward difference approximation.

The first term or the leading term in the truncation error will contribute maximum error. So,
that is why, the error of this approximation is termed as the order of accuracy i.e. power of
Δx in the leading term.

𝜕𝑓 𝑓𝑖+1 − 𝑓𝑖
| = + 𝑂(∆𝑥)
𝜕𝑥 𝑖 ∆𝑥
(Refer Slide Time: 11:27)

Similarly we will be expanding 𝑓(𝑥 − ∆𝑥) using Taylor series:


(∆𝑥) 𝜕𝑓 (∆𝑥)2 𝜕 2 𝑓 (∆𝑥)3 𝜕 3 𝑓
𝑓(𝑥 − ∆𝑥) = 𝑓(𝑥) − + − +⋯
1! 𝜕𝑥 2! 𝜕𝑥 2 3! 𝜕𝑥 3
𝜕𝑓 𝑓(𝑥) − 𝑓(𝑥 − ∆𝑥)
= + 𝑂(∆𝑥)
𝜕𝑥 ∆𝑥
𝜕𝑓 𝑓𝑖 − 𝑓𝑖−1
| = + 𝑂(∆𝑥)
𝜕𝑥 𝑖 ∆𝑥
Since we used a backward point it is known as backward difference approximation.
(Refer Slide Time: 16:33)

Now, expanding 𝑓𝑖+1 and 𝑓𝑖−1 about 𝑓𝑖 we get:


(∆𝑥) 𝜕𝑓 (∆𝑥)2 𝜕 2 𝑓 (∆𝑥)3 𝜕 3 𝑓 (∆𝑥)4 𝜕 4 𝑓
𝑓𝑖+1 = 𝑓𝑖 + + + + +⋯
1! 𝜕𝑥 2! 𝜕𝑥 2 3! 𝜕𝑥 3 4! 𝜕𝑥 4
(∆𝑥) 𝜕𝑓 (∆𝑥)2 𝜕 2 𝑓 (∆𝑥)3 𝜕 3 𝑓 (∆𝑥)4 𝜕 4 𝑓
𝑓𝑖−1 = 𝑓𝑖 − + − + +⋯
1! 𝜕𝑥 2! 𝜕𝑥 2 3! 𝜕𝑥 3 4! 𝜕𝑥 4
Then;
(∆𝑥) 𝜕𝑓 (∆𝑥)3 𝜕 3 𝑓
𝑓𝑖+1 − 𝑓𝑖−1 = 2 +2 +⋯
1! 𝜕𝑥 3! 𝜕𝑥 3
𝜕𝑓 𝑓𝑖+1 − 𝑓𝑖−1 (∆𝑥)2 𝜕 3 𝑓
| = − −⋯
𝜕𝑥 𝑖 2∆𝑥 3! 𝜕𝑥 3
𝜕𝑓 𝑓𝑖+1 − 𝑓𝑖−1
| = + 𝑂[(∆𝑥)2 ]
𝜕𝑥 𝑖 2∆𝑥
This approximation is known as central difference approximation.
Now if you want to find the second derivative, then:
(∆𝑥)2 𝜕 2 𝑓 (∆𝑥)4 𝜕 4 𝑓
𝑓𝑖+1 + 𝑓𝑖−1 = 2𝑓𝑖 + 2 +2 +⋯
2! 𝜕𝑥 2 4! 𝜕𝑥 4
which gives:

𝜕 2𝑓 𝑓𝑖+1 − 2𝑓𝑖 + 𝑓𝑖−1


2
| = + 𝑂[(∆𝑥)2 ]
𝜕𝑥 𝑖 2∆𝑥

So, this is also central difference approximation of this second derivative. The order of
accuracy of central differencing is 2.

(Refer Slide Time: 23:57)

Alternatively we can find the second derivative using central differencing by taking grid
points i, i+1/2 and i-1/2 :

𝜕 2𝑓 𝜕 𝜕𝑓
= ( )
𝜕𝑥 2 𝜕𝑥 𝜕𝑥
𝜕𝑓 𝜕𝑓
| − |
2
𝜕 𝑓 𝜕𝑥 𝑖+1⁄ 𝜕𝑥 𝑖−1⁄
2 2
= + 𝑂[(∆𝑥)2 ]
𝜕𝑥 2 ∆𝑥

𝑓𝑖+1 − 𝑓𝑖 𝑓𝑖 − 𝑓𝑖−1
𝜕 2𝑓
= ∆𝑥 − ∆𝑥 + 𝑂[(∆𝑥)2 ]
𝜕𝑥 2 ∆𝑥
𝜕 2𝑓 𝑓𝑖+1 − 2𝑓𝑖 + 𝑓𝑖−1
| = + 𝑂[(∆𝑥)2 ]
𝜕𝑥 2 𝑖 2∆𝑥

(Refer Slide Time: 27:08)

We saw that the first derivative approximation using forward and backward differencing are
first order accurate while that of the central differencing is second order accurate using two
grid points. If we use 3 grid points 𝑓𝑖+2 , 𝑓𝑖+1 and 𝑓𝑖 then we get:

(2∆𝑥) 𝜕𝑓 (2∆𝑥)2 𝜕 2 𝑓 (2∆𝑥)3 𝜕 3 𝑓 (2∆𝑥)4 𝜕 4 𝑓


𝑓𝑖+2 = 𝑓𝑖 + + + + +⋯
1! 𝜕𝑥 2! 𝜕𝑥 2 3! 𝜕𝑥 3 4! 𝜕𝑥 4
(∆𝑥) 𝜕𝑓 (∆𝑥)2 𝜕 2 𝑓 (∆𝑥)3 𝜕 3 𝑓 (∆𝑥)4 𝜕 4 𝑓
𝑓𝑖+1 = 𝑓𝑖 + + + + +⋯
1! 𝜕𝑥 2! 𝜕𝑥 2 3! 𝜕𝑥 3 4! 𝜕𝑥 4
𝜕𝑓 4(∆𝑥)3 𝜕 3 𝑓
4𝑓𝑖+1 − 𝑓𝑖+2 = 3𝑓𝑖 + 2∆𝑥 − +⋯
𝜕𝑥 3! 𝜕𝑥 3
𝜕𝑓 4𝑓𝑖+1 − 3𝑓𝑖 − 𝑓𝑖+2
| = + 𝑂[(∆𝑥)2 ]
𝜕𝑥 𝑖 2∆𝑥

This is second order accurate forward difference approximation of the first derivative. We
mostly require secondary approximation at the boundaries.
(Refer Slide Time: 34:25)

Similarly if you use 3 backward points 𝑓𝑖−2 , 𝑓𝑖−1 and 𝑓𝑖 we can write:
(2∆𝑥) 𝜕𝑓 (2∆𝑥)2 𝜕 2 𝑓 (2∆𝑥)3 𝜕 3 𝑓 (2∆𝑥)4 𝜕 4 𝑓
𝑓𝑖−2 = 𝑓𝑖 − + − + +⋯
1! 𝜕𝑥 2! 𝜕𝑥 2 3! 𝜕𝑥 3 4! 𝜕𝑥 4
(∆𝑥) 𝜕𝑓 (∆𝑥)2 𝜕 2 𝑓 (∆𝑥)3 𝜕 3 𝑓 (∆𝑥)4 𝜕 4 𝑓
𝑓𝑖−1 = 𝑓𝑖 − + − + +⋯
1! 𝜕𝑥 2! 𝜕𝑥 2 3! 𝜕𝑥 3 4! 𝜕𝑥 4
𝜕𝑓 4(∆𝑥)3 𝜕 3 𝑓
𝑓𝑖−2 −4𝑓𝑖−1 = −3𝑓𝑖 + 2∆𝑥 − +⋯
𝜕𝑥 3! 𝜕𝑥 3
𝜕𝑓 3𝑓𝑖 − 4𝑓𝑖−1 + 𝑓𝑖−2
| = + 𝑂[(∆𝑥)2 ]
𝜕𝑥 𝑖 2∆𝑥
This is second order accurate backward difference approximation of the first derivative
(Refer Slide Time: 39:48)

Till now we have seen only function of a single variable. Now we look into the discritization
of mixed derivatives. Let (i,j) be the current grid point,(i+1,j) is the forward grid point in x
direction,(i-1,j) is the backward grid point in x direction. Similarly,(i,j+1) is the forward grid
point in y direction,(i,j-1) is the backward grid point in y direction. The grid spacing is Δx
and Δy which may or may not be equal.

Writing Taylor series expansion for two variables:

(∆𝑥) 𝜕𝑓 (∆𝑦) 𝜕𝑓 (∆𝑥)2 𝜕 2 𝑓 (∆𝑦)2 𝜕 2 𝑓 2∆𝑥∆𝑦 𝜕𝑓


𝑓(𝑥 + ∆𝑥, 𝑦 + ∆𝑦) = 𝑓(𝑥, 𝑦) + + + + + +⋯
1! 𝜕𝑥 1! 𝜕𝑦 2! 𝜕𝑥 2 2! 𝜕𝑦 2 2! 𝜕𝑥𝜕𝑦

(∆𝑥) 𝜕𝑓 (∆𝑦) 𝜕𝑓 (∆𝑥)2 𝜕2 𝑓 (∆𝑦)2 𝜕2 𝑓 2∆𝑥∆𝑦 𝜕𝑓


𝑓𝑖+1,𝑗+1 = 𝑓𝑖,𝑗 + + + + + + 𝑂[(∆𝑥)3 , (∆𝑦)3 ]
1! 𝜕𝑥 1! 𝜕𝑦 2! 𝜕𝑥2 2! 𝜕𝑦2 2! 𝜕𝑥𝜕𝑦

(∆𝑥) 𝜕𝑓 (∆𝑦) 𝜕𝑓 (∆𝑥)2 𝜕2 𝑓 (∆𝑦)2 𝜕2 𝑓 2∆𝑥∆𝑦 𝜕𝑓


𝑓𝑖−1,𝑗−1 = 𝑓𝑖,𝑗 − − + 2
+ + + 𝑂[(∆𝑥)3 , (∆𝑦)3 ]
1! 𝜕𝑥 1! 𝜕𝑦 2! 𝜕𝑥 2! 𝜕𝑦2 2! 𝜕𝑥𝜕𝑦

(∆𝑥) 𝜕𝑓 (∆𝑦) 𝜕𝑓 (∆𝑥)2 𝜕2 𝑓 (∆𝑦)2 𝜕2 𝑓 2∆𝑥∆𝑦 𝜕𝑓


𝑓𝑖−1,𝑗+1 = 𝑓𝑖,𝑗 − + + 2
+ − + 𝑂[(∆𝑥)3 , (∆𝑦)3 ]
1! 𝜕𝑥 1! 𝜕𝑦 2! 𝜕𝑥 2! 𝜕𝑦2 2! 𝜕𝑥𝜕𝑦

(∆𝑥) 𝜕𝑓 (∆𝑦) 𝜕𝑓 (∆𝑥)2 𝜕2 𝑓 (∆𝑦)2 𝜕2 𝑓 2∆𝑥∆𝑦 𝜕𝑓


𝑓𝑖+1,𝑗−1 = 𝑓𝑖,𝑗 + − + 2
+ − + 𝑂[(∆𝑥)3 , (∆𝑦)3 ]
1! 𝜕𝑥 1! 𝜕𝑦 2! 𝜕𝑥 2! 𝜕𝑦2 2! 𝜕𝑥𝜕𝑦
Performing the following operation we get:
𝜕𝑓
𝑓𝑖+1,𝑗+1 + 𝑓𝑖−1,𝑗−1 − 𝑓𝑖−1,𝑗+1 − 𝑓𝑖+1,𝑗−1 = 4∆𝑥∆𝑦 + 𝑂[(∆𝑥)3 , (∆𝑦)3 ]
𝜕𝑥𝜕𝑦

𝜕𝑓 𝑓𝑖+1,𝑗+1 + 𝑓𝑖−1,𝑗−1 − 𝑓𝑖−1,𝑗+1 − 𝑓𝑖+1,𝑗−1


= + 𝑂[(∆𝑥)2 , (∆𝑦)2 ]
𝜕𝑥𝜕𝑦 4∆𝑥∆𝑦
This is the mixed derivative we found using the Taylor series expansion.

(Refer Slide Time: 49:17)

Alternatively we can come to the same conclusion by writing the mixed derivative as:

𝜕 2𝑓 𝜕 𝜕𝑓
| = ( | )
𝜕𝑥𝜕𝑦 𝑖,𝑗 𝜕𝑥 𝜕𝑦 𝑖,𝑗

and then using central differencing for the first order derivative as:

𝜕 2𝑓 𝜕 𝜕𝑓 𝜕 𝑓𝑖,𝑗+1 + 𝑓𝑖,𝑗−1
| = ( | )= ( ) + 𝑂[(∆𝑦)2 ]
𝜕𝑥𝜕𝑦 𝑖,𝑗 𝜕𝑥 𝜕𝑦 𝑖,𝑗 𝜕𝑥 2∆𝑦

1 𝜕𝑓 𝜕𝑓
= ( | − | ) + 𝑂[(∆𝑦)2 ]
2∆𝑦 𝜕𝑥 𝑖,𝑗+1 𝜕𝑥 𝑖,𝑗−1

1 𝑓𝑖+1,𝑗+1 − 𝑓𝑖−1,𝑗+1 𝑓𝑖+1,𝑗−1 − 𝑓𝑖−1,𝑗−1


= ( − ) + 𝑂[(∆𝑥)2 , (∆𝑦)2 ]
2∆𝑦 2∆𝑥 2∆𝑥
𝑓𝑖+1,𝑗+1 + 𝑓𝑖−1,𝑗−1 − 𝑓𝑖−1,𝑗+1 − 𝑓𝑖+1,𝑗−1
= + 𝑂[(∆𝑥)2 , (∆𝑦)2 ]
4∆𝑥∆𝑦
Similarly we can also use forward differencing instead of central differencing to write the first
derivative;

𝜕 2𝑓 𝜕 𝜕𝑓 𝜕 𝑓𝑖,𝑗+1 + 𝑓𝑖,𝑗
| = ( | )= ( ) + 𝑂[(∆𝑦)]
𝜕𝑥𝜕𝑦 𝑖,𝑗 𝜕𝑥 𝜕𝑦 𝑖,𝑗 𝜕𝑥 ∆𝑦

1 𝜕𝑓 𝜕𝑓
= ( | − | ) + 𝑂[(∆𝑦)]
∆𝑦 𝜕𝑥 𝑖,𝑗+1 𝜕𝑥 𝑖,𝑗

1 𝑓𝑖+1,𝑗+1 − 𝑓𝑖,𝑗+1 𝑓𝑖+1,𝑗 − 𝑓𝑖,𝑗


= ( − ) + 𝑂[(∆𝑥), (∆𝑦)]
∆𝑦 ∆𝑥 ∆𝑥
𝑓𝑖+1,𝑗+1 + 𝑓𝑖,𝑗 − 𝑓𝑖,𝑗+1 − 𝑓𝑖+1,𝑗
= + 𝑂[(∆𝑥), (∆𝑦)]
∆𝑥∆𝑦
So today we saw the forward difference approximation, backward difference approximation
and central difference approximation of the first derivative. Then we learned the central
difference approximation of second derivative. And at the last we learned the finite difference
approximation of mixed derivative.

Thank you

You might also like