Solving an elliptic PDE using finite differences Numerical Methods for PDEs Spring 2007 Jim E....
-
Upload
reynold-garrison -
Category
Documents
-
view
230 -
download
3
Transcript of Solving an elliptic PDE using finite differences Numerical Methods for PDEs Spring 2007 Jim E....
Solving an elliptic PDE using finite differences
Numerical Methods for PDEs Spring 2007
Jim E. Jones
Many physical processes can be modeled with Partial Differential Equations (PDEs)
fuu yyxx E
t
EH
t
HE
Poisson Equation modeling steady-
state temperature in 2d plate
Maxwell’s equations relating
electric and magnetic fields
2
2
22 1
tv
Wave Equation modeling wave propagation at speed v
• PDE classified by discriminant: b2-4ac.– Negative discriminant = Elliptic PDE. Example
Laplace’s equation
– Zero discriminant = Parabolic PDE. Example Heat equation
– Positive discriminant = Hyperbolic PDE. Example Wave equation
Partial Differential Equations (PDEs) :2nd order model problems
0 yyxx uu
0 xxt uu
0 ttxx uu
gfueuducubuau yxyyxyxx
• PDE classified by discriminant: b2-4ac.– Negative discriminant = Elliptic PDE. Example
Laplace’s equation
– Zero discriminant = Parabolic PDE. Example Heat equation
– Positive discriminant = Hyperbolic PDE. Example Wave equation
Partial Differential Equations (PDEs) :2nd order model problems
0 yyxx uu
0 xxt uu
0 ttxx uu
gfueuducubuau yxyyxyxx
Solving PDEs on a computer typically involves discretizing on a grid
Computers typically don’t understand continuous quantities, only discrete ones.
Rather than asking for the temperature as a function u(x,y), we seek to find an approximation to the temperature at each point on a grid.
Discretization approximates the differential problem by an algebraic one
fuu yyxx
fAu
Finite differences - derived by interpolation
x0 x1 x2
(xo,u0)
(x1,u1)
(x2,u2)
Construct polynomial interpolating data
Finite differences - derived by Lagrange interpolation
x0 x1 x2
(xo,u0)
(x1,u1)
(x2,u2)
21202
10
12101
20
02010
21
))((
))((
))((
))((
))((
))(()(
uxxxx
xxxx
uxxxx
xxxx
uxxxx
xxxxxp
Approximate 2nd derivative of u at x1 by 2nd derivative of p
Finite differences - derived by Lagrange interpolation
x0 x1 x2
(xo,u0)
(x1,u1)
(x2,u2)
)2(1
))((
2
))((
2
))((
2)(''
2102
21202
12101
02010
uuuh
uxxxx
uxxxx
uxxxx
xp
h
Finite differences - derived by Taylor’s Theorem
[Taylor’s Theorem] Suppose f and its first n derivatives are continuous on [a,b], its n+1 derivative exists on [a,b], and xo is in [a,b]. Then for any x in [a,b] there is a c(x) between x and x0 with:
10
)1(
00
0)(
)()!1(
))(()(
)(!
)()(
)()()(
n
n
n
kn
k
k
n
nn
xxn
xcfxR
xxk
xfxP
xRxPxf
Finite differences
x0 x1 x2
(xo,u0)
(x1,u1)(x2,u2)
)(24
)('''6
)(''2
)(')()(
)(24
)('''6
)(''2
)(')()(
2)4(
4
1
3
1
2
112
0)4(
4
1
3
1
2
110
cuh
xuh
xuh
xhuxuxu
cuh
xuh
xuh
xhuxuxu
Finite differences
x0 x1 x2
(xo,u0)
(x1,u1)(x2,u2)
)]()([24
)('')(2)()(
________________________________________________
)(24
)('''6
)(''2
)(')()(
)(24
)('''6
)(''2
)(')()(
2)4(
0)4(
4
12
120
2)4(
4
1
3
1
2
112
0)4(
4
1
3
1
2
110
cucuh
xuhxuxuxu
cuh
xuh
xuh
xhuxuxu
cuh
xuh
xuh
xhuxuxu
Finite differences
x0 x1 x2
(xo,u0)
(x1,u1)(x2,u2)
)]()([24
)('')(2)()(
________________________________________________
)(24
)('''6
)(''2
)(')()(
)(24
)('''6
)(''2
)(')()(
2)4(
0)4(
4
12
120
2)4(
4
1
3
1
2
112
0)4(
4
1
3
1
2
110
cucuh
xuhxuxuxu
cuh
xuh
xuh
xhuxuxu
cuh
xuh
xuh
xhuxuxu
If the 4th derivative is continuous, then the average value of u at co and c2 is attained at some c between them. (Intermediate Value Theorem)
Finite differences
x0 x1 x2
(xo,u0)
(x1,u1)(x2,u2)
)(12
)('')(2)()(
________________________________________________
)(24
)('''6
)(''2
)(')()(
)(24
)('''6
)(''2
)(')()(
)4(4
12
120
2)4(
4
1
3
1
2
112
0)4(
4
1
3
1
2
110
cuh
xuhxuxuxu
cuh
xuh
xuh
xhuxuxu
cuh
xuh
xuh
xhuxuxu
If the 4th derivative is continuous, then the average value of u at co and c2 is attained at some c between them
Finite differences
)(12
)('')(2)()( )4(4
12
120 cuh
xuhxuxuxu
x0 x1 x2
(xo,u0)
(x1,u1)(x2,u2)
Solving for u’’
)(12
)]()(2)([1
)('' )4(2
21021 cuh
xuxuxuh
xu
Finite differences
)(12
)('')(2)()( )4(4
12
120 cuh
xuhxuxuxu
x0 x1 x2
(xo,u0)
(x1,u1)(x2,u2)
Solving for u’’
)(12
)]()(2)([1
)('' )4(2
21021 cuh
xuxuxuh
xu
Same approximation we got using interpolation
Finite difference discretization based on Taylor’s approximation.
)),(),(2),((1
),(2
yhxuyxuyhxuh
yxuxx
Finite difference discretization based on Taylor’s approximation.
)),(),(2),((1
),(2
yhxuyxuyhxuh
yxuxx
Approximated derivative at a point by an algebraic equation involving function values at nearby points
By Taylor’s Theorem, the error in this approximation (the truncation error) is O(h2)
Finite difference discretization based on Taylor’s approximation.
fuu yyxx ),()),(),(),(4),(),((1
2yxfhyxuyhxuyxuhyxuyhxu
h
Error in approximation is determined by the mesh size h. Difference between differential solution and algebraic solution goes to zero as h does.
Equation for each grid point (x,y)
fAu
Simple Example
1 yyxx uu ]1,0[]1,0[
2u
on
on
Partial Differential Equation
Boundary Conditions
(0,0)
(1,1)
Simple Example
Where are the discrete u values located?
Simple Example
Where are the discrete u values located?
At grid points
Simple Example
Which u-values do we already know?
Simple Example
Which u-values do we already know?
The boundary values are =2
Simple Example
Write down the 9x9 matrix problem for computing the unknown u-values.
Simple Example
Write down the 9x9 matrix problem for computing the unknown u-values.
1 2 3
4 5 6
7 8 9
Linear System
2
2
2
2
2
2
2
2
9
8
7
6
5
4
3
2
1
2
)25(.
41
)25(.
21
)25(.
41
)25(.
21
1)25(.
21
)25(.
41
)25(.
21
)25(.
41
410100000
141010000
014001000
100410100
010141010
001014001
000100410
000010141
000001014
)25(.
1
u
u
u
u
u
u
u
u
u
1 2 3
4 5 6
7 8 9
MATLAB
MATLAB
• Debugging – does the solution “look correct”– Symmetry
– Other checks, can we set it up so we know the solution?
MATLAB
• To think about on the MLK Holiday break (and to get ready for assignment 1)– How would you code up the simple example?
– How could you allow general mesh size h?
– How could you allow general rhs and bc’s? Perhaps even functions that depend on position: sin(xy)?
– How would you verify your code is working properly?