0% found this document useful (0 votes)
42 views12 pages

Week 3 PE546 Chapter 2 Finite Difference

The document discusses numerical methods for solving partial differential equations (PDEs). It introduces finite difference approximations, which discretize derivatives to transform PDEs into algebraic equations. Three common finite difference methods are presented: forward, backward, and centered differences. Derivations show that centered differences provide an O(Δx^2) approximation to the first and second derivatives, while forward and backward differences are only O(Δx).

Uploaded by

nn1129374
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)
42 views12 pages

Week 3 PE546 Chapter 2 Finite Difference

The document discusses numerical methods for solving partial differential equations (PDEs). It introduces finite difference approximations, which discretize derivatives to transform PDEs into algebraic equations. Three common finite difference methods are presented: forward, backward, and centered differences. Derivations show that centered differences provide an O(Δx^2) approximation to the first and second derivatives, while forward and backward differences are only O(Δx).

Uploaded by

nn1129374
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/ 12

CHAPTER 2.

FINITE DIFFERENCES
Solution to Partial Differential Equations (PDEs)

Analytical solutions to PDEs are rare:

α (2 n +1)n π 2t
∂ p 1 ∂p
2
4 pinit ∞
(−1)n
(2n + 1)π x
∂x 2
=
α ∂t
⇒ p ( ) B1
x , t = p −
π

n = 0 2n + 1
e 4 L2
cos
2L

More generally we seek a numerical approximation to the PDE:

• Usually we transform the PDE into algebraic equations which are easier
to solve
• We “discretize” the derivatives
• Assume constant pressure and properties over an area/block
Solutions for PDEs ∂ 2 p 1 ∂p
=
∂x 2
α ∂t

Analytical Solution Numerical Solution


Need to solve a complex PDE Need to solve algebraic equations

p ( x, t ) time step

Grid block

Continuous Solution P Discrete Solution


P

x
x
Finite Difference Approximations

• Finite differences are used to approximate the numerical value


of a derivative at a point, x.
∂f
f ′( x) =
∂x x

f(x)

• Begin by using a truncated Taylor Series approximation of a


function
1 1
f ( x + ∆x) = f ( x) + f ′( x)∆x + f ′′( x)∆x 2 + f "'( x)∆x3 + ...
2! 3!

• Various finite difference schemes can be employed, with varying


degrees of accuracy. Three common methods employed here:
• Forward difference
• Backward difference
• Centered difference
Forward Difference Approximation
P(x) Tangent line
Secant line

∂P P( x + ∆x) − P( x)

∂x forward ∆x

x x+∆x
x

• Derivative is defined as the “slope of the line tangent to the curve”

• This is difficult because you need two points to make a line

• Secant connects P(x) to P(x+∆x). Slope of the secant line is the “rise”
over the “run”

• Using smaller ∆x should give more accuracy to slope of the tangent


line, in fact they are the same in the limit that ∆x 0
Derivation of Forward Difference

Recall a Taylor Series:


∂P 1 ∂2 P 1 ∂3 P
P( x + ∆x) = P( x) + ∆x + ( ∆x ) 2
+ ( ∆x ) 3
+
∂x x 2! ∂x x
2
3! ∂x x
3

Re-arrange for the first derivative:

∂P P( x + ∆x) − P ( x) 1 ∂2 P 1 ∂3 P
= − ( ∆x ) + ( ∆x ) 2
+
∂x x ∆x 2! ∂x x
2
3! ∂x x
3

forward difference approximation truncation error

Forward approximation is as before; error is proportional to ∆x:

∂P P( x + ∆x) − P( x) P" P "'


≈ R= (∆x) + (∆x) 2 + = O(∆x)
∂x forward ∆x 2! 3!
Backward Difference Approximation for

Secant line
Tangent line
P(x)

∂P P( x) − P( x − ∆x)

∂x backward ∆x

x-∆x x

• Secant now connects P(x) to P(x-∆x). Slope of the secant line is the
“rise” over the “run”

• Using smaller ∆x should give more accuracy to slope of the tangent


line, in fact they are the same in the limit that ∆x 0

• Backward difference is not necessarily “better” or “worse” than forward


difference
Derivation of Backward Difference

Even terms are now negative in Taylor Series:


∂P 1 ∂2 P 1 ∂3 P
P( x − ∆x) = P( x) − ∆x + ( ∆x ) 2
− ( ∆x ) 3
+
∂x x 2! ∂x x
2
3! ∂x x
3

Re-arrange for the first derivative:

∂P P( x) − P ( x − ∆x) 1 ∂2 P 1 ∂3 P
= + ( ∆x ) − ( ∆x ) 2
+
∂x x ∆x 2! ∂x x
2
3! ∂x x
3

backward difference approximation truncation error

Error in the backward difference approximation is proportional to ∆x, just


like the forward difference:

∂P P( x) − P ( x − ∆x) P" P "'


≈ R= (∆x) − (∆x) 2 + = O(∆x)
∂x backward ∆x 2! 3!
Central Difference Approximation

Tangent
P(x) line
Secant line

∂P P ( x + ∆x) − P( x − ∆x)

∂x centered 2∆x

x-∆x x x+∆x

• Secant now connects P(x+∆x) to P(x-∆x). Slope of the secant line is the
“rise” over the “run”

• Using smaller ∆x should give more accuracy to slope of the tangent


line, in fact they are the same in the limit that ∆x 0

• Centered difference is potentially more accurate than forward or


backward difference
Derivation of Central Difference Approximation

You can subtract forward and backward Taylor series to get centered

∂P 1 ∂2 P 1 ∂3 P
P( x + ∆x) = P( x) + ∆x + ( ∆x ) 2
+ ( ∆x ) 3
+
∂x x 2! ∂x x
2
3! ∂x x
3

∂P 1 ∂2 P 1 ∂3 P
− P( x − ∆x) = P( x) − ∆x + ( ∆x ) 2
− ( ∆x ) 3

∂x x 2! ∂x 2 x 3! ∂x 3 x

∂P 2 ∂3 P
P( x + ∆x) − P( x − ∆x) = 2 ∆x + ( ∆x ) 3
+ ...
∂x x 3! ∂x x
3

Rearranging gives the centered approximation with only O(∆x2) error!

∂P P( x + ∆x) − P( x − ∆x) P "'


≈ R=− (∆x) 2 + = O(∆x 2 )
∂x centered 2∆x 3!
What about 2nd Derivative?
• Can derive a forward or backward, 2nd derivative
• Here, we’ll derive a centered difference approximation
• Add forward and backward Taylor series together

∂P 1 ∂2 P 1 ∂3 P
P( x + ∆x) = P( x) + ∆x + ( ∆x ) 2
+ ( ∆x ) 3
+
∂x x 2! ∂x 2 x 3! ∂x 3 x

∂P 1 ∂2 P 1 ∂3 P
+ P( x − ∆x) = P ( x) − ∆x + (∆x) −
2
(∆x)3 + ...
∂x x 2! ∂x x
2
3! ∂x x
3

∂2 P
P( x + ∆x) + P( x − ∆x) = 2 P( x) + 2 (∆x) 2 + ...
∂x x

Centered difference approximation is O(∆x2)


P( x + ∆x) − P( x) P( x) − P( x − ∆x)

∂2 P P( x + ∆x) − 2 P ( x) + P ( x − ∆x) (∆x) (∆x)
≈ =
∂x 2 centered (∆x) 2 (∆x)
Summary of Important Finite Difference
Approximations

Derivative Finite Difference Approximation Type Error


∂P P ( t + ∆t ) − P ( t ) Forward Difference O ( ∆t )
∂t ∆t
∂P P ( t ) − P ( t − ∆t ) Backward Difference O ( ∆t )
∂t ∆t
∂P P ( t + ∆t ) − P ( t − ∆t ) Centered Difference O ( ∆t 2 )
∂t 2∆t
∂2 P P ( x + ∆x ) − 2 P ( x ) + P ( x − ∆x ) Centered Difference O ( ∆x 2 )
∂x 2 ∆x 2

You might also like