You are on page 1of 17

'

&
$
%
Matrix Form of Finite Dierence Schemes
T. H. Pulliam
Stanford University
1
'
&
$
%
Non-Periodic Wave Equation
Example 1: Linear Wave Equation, non-periodic, 11 Grid Points
u
t
+ a
u
x
= 0
BC : u(0, t) = u
left
IC : u(x, 0) = g(x)
Second Order Central Dierencing
u
j
t
+
a
2x
(u
j1
+ u
j+1
) = 0
1. Assume a vector of 10 grid points of computed data
u = [u
2
, u
3
, u
4
, u
5
, u
6
, u
7
, u
8
, u
9
, u
10
, u
11
]
T
2. Boundary condition: u
1
= u
left
2
'
&
$
%
Dierence Equations
u
j
t
+
a
2x
_
u
j1
+ u
j+1
_
= 0
u
2
t
+
a
2x
{ 0 u
3
0 0 0 0 0 0 0 0 }
a
2x
u
1
= 0
u
3
t
+
a
2x
{ u
2
0 u
4
0 0 0 0 0 0 0 } = 0
u
4
t
+
a
2x
{ 0 u
3
0 u
5
0 0 0 0 0 0 } = 0
u
5
t
+
a
2x
{ 0 0 u
4
0 u
6
0 0 0 0 0 } = 0
u
6
t
+
a
2x
{ 0 0 0 u
5
0 u
7
0 0 0 0 } = 0
u
7
t
+
a
2x
{ 0 0 0 0 u
6
0 u
8
0 0 0 } = 0
u
8
t
+
a
2x
{ 0 0 0 0 0 u
7
0 u
9
0 0 } = 0
u
9
t
+
a
2x
{ 0 0 0 0 0 0 u
8
0 u
10
0 } = 0
u
10
t
+
a
2x
{ 0 0 0 0 0 0 0 u
9
0 u
11
} = 0
u
11
t
+
a
2x
{ 0 0 0 0 0 0 0 0 u
10
0 } +
a
2x
u
12
= 0
1. BC: u
1
= u
left
2. Note the u
12
does not exist, so we need to do something.
3
'
&
$
%
Dierence Equations, With Correct BC
1. Replace equation for u
11
with the 1
st
backward dierence scheme
u
11
t
+
a
2x
[2u
10
+ 2u
11
] = 0
u
2
t
+
a
2x
{ 0 u
3
0 0 0 0 0 0 0 0 }
a
2x
u
left
= 0
u
3
t
+
a
2x
{ u
2
0 u
4
0 0 0 0 0 0 0 } = 0
u
4
t
+
a
2x
{ 0 u
3
0 u
5
0 0 0 0 0 0 } = 0
u
5
t
+
a
2x
{ 0 0 u
4
0 u
6
0 0 0 0 0 } = 0
u
6
t
+
a
2x
{ 0 0 0 u
5
0 u
7
0 0 0 0 } = 0
u
7
t
+
a
2x
{ 0 0 0 0 u
6
0 u
8
0 0 0 } = 0
u
8
t
+
a
2x
{ 0 0 0 0 0 u
7
0 u
9
0 0 } = 0
u
9
t
+
a
2x
{ 0 0 0 0 0 0 u
8
0 u
10
0 } = 0
u
10
t
+
a
2x
{ 0 0 0 0 0 0 0 u
9
0 u
11
} = 0
u
11
t
+
a
2x
{ 0 0 0 0 0 0 0 0 2u
10
2u
11
} = 0
4
'
&
$
%
Matrix Form, Second Order Central Dierencing
The previous set of equations can be rewitten in a matrix form:
u
t
+
a
2x
[A] u + bc = 0
with
[A] =
{ 0 1 0 0 0 0 0 0 0 0 }
{ 1 0 1 0 0 0 0 0 0 0 }
{ 0 1 0 1 0 0 0 0 0 0 }
{ 0 0 1 0 1 0 0 0 0 0 }
{ 0 0 0 1 0 1 0 0 0 0 }
{ 0 0 0 0 1 0 1 0 0 0 }
{ 0 0 0 0 0 1 0 1 0 0 }
{ 0 0 0 0 0 0 1 0 1 0 }
{ 0 0 0 0 0 0 0 1 0 1 }
{ 0 0 0 0 0 0 0 0 2 2 }
and bc =
_

a
2x
u
left
, 0, 0, 0, 0, 0, 0, 0, 0, 0

T
A Coupled System of ODEs
Matrix Notation: A = B(10 : b, c, 1) with
b = [1, 1, 1, 1, 1, 1, 1, 1, 2] and c = [0, 0, 0, 0, 0, 0, 0, 0, 0, 2]
5
'
&
$
%
Matrix Form: Non-Periodic Diusion Equation
Example 2: Diusion Equation, non-periodic, 11 Grid Points
u
t
=

2
u
x
2
BC : u(0, t) = u
left
, u(1, t) = u
right
IC : u(x, 0) = g(x)
Second Order Central Dierencing
u
j
t
=

x
2
(u
j1
2u
j
+ u
j+1
)
Assume a vector of 9 grid point of computed data
u = [u
2
, u
3
, u
4
, u
5
, u
6
, u
7
, u
8
, u
9
, u
10
]
T
Boundary condition: u
1
= u
left
and u
11
= u
right
6
'
&
$
%
Dierence Equations
u
j
t
=

x
2
(u
j1
2u
j
+ u
j+1
)
u
2
t
=

x
2
{ 2u
2
u
3
0 0 0 0 0 0 0 } +

x
2
u
left
u
3
t
=

x
2
{ u
2
2u
3
u
4
0 0 0 0 0 0 }
u
4
t
=

x
2
{ 0 u
3
2u
4
u
5
0 0 0 0 0 }
u
5
t
=

x
2
{ 0 0 u
4
2u
5
u
6
0 0 0 0 }
u
6
t
=

x
2
{ 0 0 0 u
5
2u
6
u
7
0 0 0 }
u
7
t
=

x
2
{ 0 0 0 0 u
6
2u
7
u
8
0 0 }
u
8
t
=

x
2
{ 0 0 0 0 0 u
7
2u
8
u
9
0 }
u
9
t
=

x
2
{ 0 0 0 0 0 0 u
8
2u
9
u
10
}
u
10
t
=

x
2
{ 0 0 0 0 0 0 0 u
9
2u
10
} +

x
2
u
right
Note boundary conditions are included.
7
'
&
$
%
Matrix Form, Second Order Central Dierencing
The previous set of equations can be rewitten in a matrix form:
u
t
=

x
2
[A] u + bc
with
[A] =
{ 2 1 0 0 0 0 0 0 0 }
{ 1 2 1 0 0 0 0 0 0 }
{ 0 1 2 1 0 0 0 0 0 }
{ 0 0 1 2 1 0 0 0 0 }
{ 0 0 0 1 2 1 0 0 0 }
{ 0 0 0 0 1 2 1 0 0 }
{ 0 0 0 0 0 1 2 1 0 }
{ 0 0 0 0 0 0 1 2 1 }
{ 0 0 0 0 0 0 0 1 2 }
and bc =

x
2
[u
left
, 0, 0, 0, 0, 0, 0, 0, u
right
]
T
A Coupled System of ODEs
Matrix Notation: A = B(9 : 1, 2, 1)
8
'
&
$
%
Matrix Form: Periodic Wave Equation
Example 3: Linear Wave Equation, periodic, 11 Grid Points
u
t
+ a
u
x
= 0
BC : u(0, t) = u(2, t) IC : u(x, 0) = g(x)
Second Order Central Dierencing
u
j
t
+
a
2x
(u
j1
+ u
j+1
) = 0
Assume a vector of 11 grid points of computed data
u = [u
1
, u
2
, u
3
, u
4
, u
5
, u
6
, u
7
, u
8
, u
9
, u
10
, u
11
]
T
9
'
&
$
%
Dierence Equations
u
j
t
+
a
2x
_
u
j1
+ u
j+1
_
= 0
u
1
t
+
a
2x
{ 0 u
2
0 0 0 0 0 0 0 0 u
11
} = 0
u
2
t
+
a
2x
{ u
1
0 u
3
0 0 0 0 0 0 0 0 } = 0
u
3
t
+
a
2x
{ 0 u
2
0 u
4
0 0 0 0 0 0 0 } = 0
u
4
t
+
a
2x
{ 0 0 u
3
0 u
5
0 0 0 0 0 0 } = 0
u
5
t
+
a
2x
{ 0 0 0 u
4
0 u
6
0 0 0 0 0 } = 0
u
6
t
+
a
2x
{ 0 0 0 0 u
5
0 u
7
0 0 0 0 } = 0
u
7
t
+
a
2x
{ 0 0 0 0 0 u
6
0 u
8
0 0 0 } = 0
u
8
t
+
a
2x
{ 0 0 0 0 0 0 u
7
0 u
9
0 0 } = 0
u
9
t
+
a
2x
{ 0 0 0 0 0 0 0 u
8
0 u
10
0 } = 0
u
10
t
+
a
2x
{ 0 0 0 0 0 0 0 0 u
9
0 u
11
} = 0
u
11
t
+
a
2x
{ u
1
0 0 0 0 0 0 0 0 u
10
0 } = 0
1. Because of the periodic BC: At j = 1 we need u
j1
= u
0
= u
11
2. Likewise at j = 11 we need u
j+1
= u
12
= u
1
10
'
&
$
%
Matrix Form, Second Order Central Dierencing
The previous set of equations can be rewitten in a matrix form:
u
t
+
a
2x
[A] u = 0
with
[A] =
{ 0 1 0 0 0 0 0 0 0 0 1 }
{ 1 0 1 0 0 0 0 0 0 0 0 }
{ 0 1 0 1 0 0 0 0 0 0 0 }
{ 0 0 1 0 1 0 0 0 0 0 0 }
{ 0 0 0 1 0 1 0 0 0 0 0 }
{ 0 0 0 0 1 0 1 0 0 0 0 }
{ 0 0 0 0 0 1 0 1 0 0 0 }
{ 0 0 0 0 0 0 1 0 1 0 0 }
{ 0 0 0 0 0 0 0 1 0 1 0 }
{ 0 0 0 0 0 0 0 0 1 0 1 }
{ 1 0 0 0 0 0 0 0 0 1 0 }
A Coupled System of ODEs
Matrix Notation: A = B
p
(11 : 1, 0, 1)
11
'
&
$
%
Diusion Equation: Neumann BC
Example 4: Diusion Equation, Right BC Neunamm, 11 Grid Points
u
t
=

2
u
x
2
BC : u(0, t) = u
left
,
u(1, t)
x
=
_
u
x
_
b
IC : u(x, 0) = g(x)
Second Order Central Dierencing
u
j
t
=

x
2
(u
j1
2u
j
+ u
j+1
)
Assume a vector of 9 grid point of computed data
u = [u
2
, u
3
, u
4
, u
5
, u
6
, u
7
, u
8
, u
9
, u
10
]
T
At Right Boundary: Derivative is given instead of point value.
12
'
&
$
%
Boundary Condition Implementation
1. The Interior Dierence Equations are the same as before, except
for the equation at j = 10
2. Design of Boundary Operator for Neumann BC
(a) At General Point j folding in the Neumann Condition with
local point values
_

2
u
x
2
_
j

_
1
x
2
(au
j1
+ bu
j
) +
c
x
_
u
x
_
j+1
_
= ?
13
'
&
$
%
x x
2
x
3
x
4

u
j
_
u
x
_
j
_

2
u
x
2
_
j
_

3
u
x
3
_
j
_

4
u
x
4
_
j
x
2

2
u
x
2
_
j
1
au
j1
a a (-1)
1
1
a (-1)
2

1
2
a (-1)
3

1
6
a (-1)
4

1
24
bu
j
b
x c
_
u
x
_
j+1
c c (1)
1
1
c (1)
2

1
2
c (1)
3

1
6
(b) Solving for a, b, and c, we obtain the following rst-order
operator, at j = 10:
(
xx
u)
10
=
1
3x
2
(2u
9
2u
10
) +
2
3x
_
u
x
_
11
14
'
&
$
%
Matrix Form
The previous set of equations can be rewitten in a matrix form:
u
t
=

x
2
[A] u + bc
with
[A] =
{ 2 1 0 0 0 0 0 0 0 }
{ 1 2 1 0 0 0 0 0 0 }
{ 0 1 2 1 0 0 0 0 0 }
{ 0 0 1 2 1 0 0 0 0 }
{ 0 0 0 1 2 1 0 0 0 }
{ 0 0 0 0 1 2 1 0 0 }
{ 0 0 0 0 0 1 2 1 0 }
{ 0 0 0 0 0 0 1 2 1 }
{ 0 0 0 0 0 0 0
2
3

2
3
}
bc =

x
2
_
u
left
, 0, 0, 0, 0, 0, 0, 0,
2x
3
_
u
x
_
b

T
Matrix Notation: A = B(9 : a, b, 1)
with a =
_
1, 1, 1, 1, 1, 1, 1, 1,
2
3

and
b =
_
2, 2, 2, 2, 2, 2, 2, 2,
2
3

15
'
&
$
%
Matrix Form: Compact Schemes
1. For Example: the 3 point 4
th
Order scheme
_
u
x
_
j1
+ 4
_
u
x
_
j
+
_
u
x
_
j+1

3
x
(u
j1
+ u
j+1
) = O(x
4
)
2. In Matrix Form:
B(1, 4, 1)
x

u =
3
x
B(1, 0, 1)

u +
_

bc
_
in which Dirichlet boundary conditions (put into
_

bc
_
) have been
imposed.
16
'
&
$
%
3. Therefore, to apply the compact scheme
(a) We need to form the right hand side above (A resulting
vector)
(b) Then, do a matrix inversion to get the resulting nite
dierence term
u
x j
(c)
x

u = B(1, 4, 1)
1
_
3
x
B(1, 0, 1)

u +
_

bc
__
17

You might also like