You are on page 1of 13

# CE 341/441 - Lecture 14 - Fall 2004

LECTURE 14
PRACTICAL ISSUES IN APPLYING FINITE DIFFERENCE APPROXIMATIONS
Derivatives of Variable Coefficients
• Consider the term
d
df ( x )
------  g ( x ) -------------
dx 
dx 

where g is a coefficient which is a function of x
• Proceed in steps. First let:
df
u ≡ g ( x ) -----dx

• Now evaluate:
(1)
du
------ = u i
dx

p. 14.1

i + --2 2 (1) g 1f 1 i – --.Lecture 14 . hi i – --. h i + 1  2  fi – fi – 1 = g 1  ---------------------. i + --.Fall 2004 hi hi+1 x i-1/2 i-1 i u (1) ui • Now evaluate u 1 i + --2 and u x i+1/2 i+1 1 i + --2 –u 1 i – --2 = -----------------------------1 --.i – --2 2  f i + 1 – f i = g 1  ---------------------.( h i + h i + 1 ) 2 1 i – --2 u u 1 i + --2 1 i – --2 = g = (1) 1f 1 i + --. 14.  2 p.CE 341/441 .2 .

14.Lecture 14 .– f i ----------------------.+ ---------------. then the approximation reduces to: (1) ui 1 = -----2 f i + 1 g 1 – f i  g 1 + g 1 + f i – 1 g 1  i + --i – --- i – --i + --h 2 2 2 2 • Example Applications with variable coefficients: • Fluids: spatially varying viscosities/diffusivities • Solids: spatially varying elasticities p.3 .Fall 2004 • Hence (1) ui where g i + 1/2 g i – 1/2 g i + 1/2 g i – 1/2 = f i + 1 ----------------------.CE 341/441 .+ f i – 1 ---------------h avg h i + 1 h avg h i h avg h i + 1 h avg h i hi + hi + 1 h avg ≡ ---------------------2 • When h = h i + 1 = h i .

4 ∆x i+1. j fi+2. j+2 fi+2 .Lecture 14 . j i. j+2 i. 14. j+1 ∆y i-2. j fi .Fall 2004 Two Dimensional Finite Difference Approximations • Define nodes in a two-dimensional plane with • i = spatial index in the x -direction • j = spatial index in the y -direction yf fi .CE 341/441 . j i. j-1 i. j+2 i. j+2 i+2. j x . j-2 p. j i+2. j i-1.

j + 1 – 2 f i.Lecture 14 .Fall 2004 • When taking partial derivatives w.CE 341/441 . 14. j + f i – 1.r. j – 2 f i. j f i. j = -----------------------------------2∆x and 2 ∂ f --------2∂x i. j f i + 1. j – f i – 1.5 . j = ------------------------------------------------------2 ∆x i. we hold y constant ∂f -----∂x i. x . j – 1 = ------------------------------------------------------2 ∆y • Similarly 2 ∂ f --------2∂y p. j + f i.t. j f i + 1.

j-1 j–1 – 4 f i. j ) . j + f i – 1. j + f i. j -4 1 p.+ --------2∂x ∂y i. j 1 = -----2 ( f i + 1.Lecture 14 .Fall 2004 Example 1 • Consider Laplace’s equation and ∆x = ∆y = h : ∇2 f ∂2 f ∂2 f = --------2. j+1 1 1 h2 fi-1. 14. j 1 fi.CE 341/441 . • This may be viewed as follows in terms of a molecule: fi . h j+1 + f i. j 1 fi .6 fi+1. j ⇒ 2 ∇ f i.

j )   ∂x ∆x ∂x ⇒ p. j – 2 f i. --------2- ∂x  ∂x  ∂x ⇒ 4 2 ∂ 1 ∂ f --------4. 14.= -------2.Lecture 14 .Fall 2004 Example 2 • Let’s consider: 4 4 4 ∂ f ∂ f ∂ f ∇ f = ∇ ( ∇ f ) = --------4. 4 2 2 ∂ f ∂ ∂ f  • Obtain --------4.+ 2 ---------------+ -------2 2 4 ∂x ∂y ∂x ∂y 4 2 2 • Draw a molecule diagram for the 2nd order central difference formulation.by finding -------2. j + f i – 1.7 .= -------2. --------2.CE 341/441 .( f i + 1. --------2- ∂x  ∂x  ∂x 2 2 4 ∂ ∂ f  ∂ f --------4.

( f i + 2.= --------2.( f i + 1.( f i + 1.8 -4 1 . j )  ∆x ∆x ∂x 2 – --------2.Fall 2004 2 2 2 4  1 ∂ ∂ ∂ ∂ f --------4. j )   ∆x ⇒ 4 1 ∂ f --------4.( f i. --------2.CE 341/441 . j – 2 f i + 1. j – 4 f i – 1.Lecture 14 . j )  ∆x  ∂x ∂x ∂x ∂x ⇒ 4 1 1 ∂ f --------4.( f i – 2. j – 2 f i. j + 6 f i. j ) + -------2. j + f i + 2. j – 4 f i + 1.( f i – 1. j – 2 f i – 1. j + f i – 2. j + f i.= --------4. -------2. j ) ∆x 1 + --------2. j + f i – 1.( f i. j ) – 2 -------2.= --------2. 14. j ) ∆x ∂x 1 ∆x4 1 -4 6 p.

j – 2 – 4 f i. 14. j + 1 + f i. j + 2 ) ∆y dy 1 -4 1 ∆y4 6 -4 1 p.= --------4.9 .Lecture 14 . j – 4 f i. j – 1 + 6 f i.Fall 2004 • Similarly: 4 1 ∂ f --------4.( f i.CE 341/441 .

j + f i + 1.Fall 2004 • Evaluation of the mixed derivative: 2 2 4 ∂ ∂ f  ∂ f ---------------. j + f i + 1.( f i – 1. j – 1 – 2 f i. j – 1 – 2 f i – 1.CE 341/441 . --------2- 2 2 ∂y  ∂x  ∂x ∂y ⇒ 4 2 1 ∂ ∂ f -------2. j + 1 ) ∆y p.( f i.= -------2.Lecture 14 . j ) = ---------------2 2   ∂y ∆x ∂x ∂y ⇒ 4 1 1 ∂ f --------2. 14. --------2.( f i + 1. j + f i. j + 1 ) ---------------= 2 2 ∆x ∆y ∂x ∂y 2 – --------2.10 . j + 1 ) ∆y 1 + --------2. j + f i – 1.--------2. j – 1 – 2 f i + 1. j – 2 f i.( f i – 1.

Lecture 14 . j – 1 2 2 ∆x ∆y ∂x ∂y – 2 f i. j ] • This then produces the following module 1 ∆x2 ∆y2 1 -2 1 -2 4 -2 1 -2 1 p. j + 1 + f i + 1. j + f i + 1. j – 1 – 2 f i + 1. 14. j – 1 + 4 f i. j + 1 2 2 i – 1.CE 341/441 .Fall 2004 ⇒ 4 1 ∂ f ------------------[ f ---------------= – 2 f i – 1. j + f i – 1.11 . j – 2 f i.

14.Lecture 14 .Fall 2004 • We can also obtain this module as follows: ∂ 2f ∂x2 = ∂2f ∂y2 1 ∆x2 [ 1 -2 1 ] 1 = 1 ∆y2 -2 1 • Therefore 1 -2 1 -2 4 -2 1 -2 1 1 ∂2 ∂2f ∂y2 ∂x2 = 1 ∆x2 ∆y2 -2 x 1 -2 1 = 1 ∆x2 ∆y2 1 p.CE 341/441 .12 .

CE 341/441 .Lecture 14 . we must add up modules: 4 4 4 ∂ f ∂ f ∂ f + -------∇ f = --------4.Fall 2004 • To obtain ∇ 4 f .+ 2 ---------------2 2 4 ∂x ∂y ∂x ∂y 4 • If ∆x = ∆y = h then: 1 1 h4 1 2 -8 2 -8 20 -8 2 -8 2 1 p.13 1 . 14.