Information Technology Reference
In-Depth Information
Algorithm 7.7
The Scheme for the Diffusion Equation with u .0; t /
D
D 0 .t /
and u .1; t / D D 1 .t / .
SET INITIAL CONDITION :
u i D
I.x i /;
for i
D
0;:::;n
t =x 2
˛
D
t 0 D
0
COMPUTE CONSTANT COEFFICIENT MATRIX :
A i;j D
0 for i; j
D
0; 1; : : : ; n
A 0;0 D
1
A n;n D
1
for i
D
1;:::;n
1
A i;i 1
D
˛ , A i;i C 1
D
˛
FACTORIZE MATRIX :
c , d = factorize ( p , q , r )
for ` D 1; 1; : : : ; m
t ` D t ` 1 C t
FILL RIGHT - HAND SIDE :
b 0 D
A i;i
D
1
C
D 0 .t ` /
b n D
D 1 .t ` /
D
for i
1;:::;n
1
/ u ` 1
i
// u ` 1
i
/ u ` 1
i C 1
b i D
˛.1
C
.1
2˛.1
C
˛.1
C
1
t .f `
i
/f ` 1
i
C
.1
/
SOLVE LINEAR SYSTEM :
u= backsubstitution ( b , r , c , d )
u i u
Looking at this scheme, we realize that if we set D 0, we recover the explicit
forward Euler scheme. 19 Setting D 1, we get the implicit backward Euler scheme,
and setting D 1=2, we arrive at the Crank-Nicolson scheme. Therefore, in a
program it can be wise to implement the scheme and then just choose a value to
recover one of the three specialized schemes.
The value D 0 is a special case, since then we have a diagonal matrix system
and there is hence no need to invoke a factorization and back-substitution procedure.
In programs we might use the scheme for all implicit schemes ( ¤ 0) and offer
a separate and simpler implementation for the explicit scheme ( D 0).
Finally, we summarize our numerical methods for the diffusion PDE by listing
the most general computational procedure: Algorithm 7.7 , expressing the scheme.
19 Scheme ( 7.147 ) with
D
0 equals (7.90) if in the latter we exchange ` with `
1 and `
C
1
with `.
 
Search WWH ::




Custom Search