Professional Documents
Culture Documents
Finite Differences PDF
Finite Differences PDF
0 X
x0 x1 xi 1 xi xi+1 xN 1 xN
First-order derivatives
u u(x + x) u(x) u(x) u(x x)
(x) = lim = lim
x x0 x x0 x
u(x + x) u(x x)
= lim (by definition)
x0 2x
Approximation of first-order derivatives
Geometric interpretation
u forward ba
kward
entral u
ui+1 ui
x i x forward difference
u
ui ui1
u
ui+1 ui1
x i 2x central difference
xi 1 xi xi+1 x
P (xxi )n nu
Taylor series expansion u(x) = n! xn i , u C ([0, X])
n=0
u (x)2 2 u (x)3 3 u
T1 : ui+1 = ui + x + 2
+ 3
+ ...
x
i 2 x i 6 x i
u (x)2 2 u (x)3 3 u
T2 : ui1 = ui x + + ...
x i 2 x2 i 6 x3 i
Analysis of truncation errors
=
x i x x
di+1/2 ui+1 (di+1/2 + di1/2 )ui + di1/2 ui1
=
(x)2
Approximation of mixed derivatives
2u u u y
2D: xy = x y = y x
u u
2u
y y
i+1,j i1,j
= + O(x)2 yj +1
xy i,j 2x
yj
u ui+1,j+1 ui+1,j1
= + O(y)2 yj 1
y i+1,j 2y
u ui1,j+1 ui1,j1
= + O(y)2
y i1,j 2y xi 1 xi xi+1 x
u0 = a cx2 = u1 u0 bx
u1 = a + bx + cx2 3u0 + 4u1 u2
b=
u2 = a + 2bx + 4cx2 2x
Analysis of the truncation error
u ui + ui+1 + ui+2
One-sided approximation
x i x
u (x)2 2 u (x)3 3 u
ui+1 = ui + x + + + ...
x i 2 x2 i 6 x3 i
2
2 3
3
u (2x) u (2x) u
ui+2 = ui + 2x + + + ...
x i 2 x2 i 6 x3 i
ui +ui+1 +ui+2 ++ u x 2u
x = x ui + ( + 2) x i + 2 ( + 4) x2 + O(x2 )
i
Second-order accurate if + + = 0, + 2 = 1, + 4 = 0
3ui +4ui+1 ui+2
= 23 , = 2, = 21 u
x i = 2x + O(x2 )
Application to second-order derivatives
2u ui + ui+1 + ui+2
One-sided approximation
x2 i x2
u (x)2 2 u (x)3 3 u
ui+1 = ui + x + + + ...
x i 2 x2 i 6 x3 i
2
2 3
3
u (2x) u (2x) u
ui+2 = ui + 2x + + + ...
x i 2 x2 i 6 x3 i
ui +ui+1 +ui+2 ++ +2 u +4 2u
x2 = x2 ui + x x i + 2 x2 + O(x)
i
First-order accurate if + + = 0, + 2 = 0, + 4 = 2
u
ui 2ui+1 +ui+2
= 1, = 2, =1 x i = x2 + O(x)
High-order approximations
u 2ui+1 + 3ui 6ui1 + ui2
= + O(x)3 backward difference
x i 6x
u ui+2 + 6ui+1 3ui 2ui1
= + O(x)3 forward difference
x i 6x
u ui+2 + 8ui+1 8ui1 + ui2
= + O(x)4 central difference
x i 12x
2u ui+2 + 16ui+1 30ui + 16ui1 ui2
= + O(x)4 central difference
x2 i 12(x) 2
One-dimensional mesh 0 1
x0 x1 xi 1 xi xi+1 xN 1 xN
1
ui u(xi ), fi = f (xi ) xi = ix, x = , i = 0, 1, . . . , N
N
Central difference approximation O(x)2
ui1 2ui +u i+1
= fi , i = 1, . . . , N 1
(x)2
u0 = uN = 0 Dirichlet boundary conditions
Result: the original PDE is replaced by a linear system for nodal values
Example: 1D Poisson equation
Matrix form Au = F A RN 1N 1 u, F RN 1
2 1 u1 f1
1 1 2 1 u2 f2
A= 1 2 1 , u= u3 , F = f3
(x)2 ...
1 2 uN 1 fN 1
u
Non-homogeneous Neumann BC x (1) = g1 only F changes
uN +1 uN 1
= g1 uN +1 = uN 1 + 2xg1
2x
uN 1 2uN + uN +1 uN 1 + uN 1 g1
= fN = fN +
(x)2 (x)2 2 x
u
Non-homogeneous Robin BC x (1) + u(1) = g2 A and F change
uN +1 uN 1
+ uN = g2 uN +1 = uN 1 2xuN + 2xg2
2x
uN 1 2uN + uN +1 uN 1 + (1 + x)uN 1 g2
= fN = fN +
(x)2 (x)2 2 x
Example: 2D Poisson equation
y h h ve-point sten
il
Boundary value problem 1
2 u2 2 u2 = f in = (0, 1) (0, 1) yj +1
x y
h
yj
u=0 on = h
yj 1
1
Uniform mesh: x = y = h, N= h xi 1 xi xi+1 x
0 1
2D Poisson equation 3
2 u2 2 u2 = f in
x y
4 R 0 Q 2
u = g0 on Q
h
P 1
Difference equation
stencil of Q
u1 + u2 4u0 + u3 + u4
= f0
h2 curvilinear boundary
Linear interpolation
u4 (h ) + u0 h
u(R) = = g0 (R) u4 = u0 + g0 (R)
h h h
h
Substitution yields u1 + u2 4 + h u0 + u3 = h2 f0 + g0 (R) h
inverse mapping
y a b a b
physi
al domain
omputational domain
body-tted grid
artesian grid
x
u u u u
Derivative transformations , ,... , ,...
x y
| {z } | {z }
difficult to compute easy to compute
PDE transformations for a direct mapping
Direct mapping = (x, y), = (x, y)
Chain rule u u u u u u
= + , = +
x x x y y y
2 2
2u u 2 u 2 2 u 2 u 2 u
= + +2 + 2 + 2
x2 x2 x2 x x x x
2 2
2u u 2 u 2 2 u 2 u 2 u
= + +2 + 2 + 2
y 2 y 2 y 2 y y y y
x x y y
Metrics transformations , , , , , ,
x y x y
| {z } | {z }
unknown known
Chain rule
u u x u y u x y u
= x + y x
=
y
u u x u y u x u
= x + y y
| {z }
J
(x,y)
where J = (,) is the Jacobian which can be inverted using Cramers rule
Derivative transformations
u 1 u y u y u 1 u x u x
= , =
x det J y det J
Direct versus inverse mapping
x x
x = x(, ) dx = d + d dx x x
d
=
y y
y = y(, ) y y dy d
dy = d + d
1
x x y
x y 1 x
= =
y y det J y x
x y