Information Technology Reference
In-Depth Information
Algorithm 7.3
D
0
.t /
and u
0
.1; t /
Diffusion Equation with u
.0; t /
D
D
N
1
.t /
.
t =x
2
SET INITIAL CONDITIONS
:
u
i
D
˛
D
I.x
i
/;
for i
D
0;:::;n
t
0
D
0
for `
D
0; 1; : : : ; m
1
t
`
C
1
D
t
UPDATE ALL INNER POINTS
:
for i
t
`
C
D
1;:::;n
1
˛
u
i
1
u
i
C
1
u
`
C
1
i
u
i
C
2
u
i
C
tf
`
i
D
C
INSERT
D
IRICHLET BOUNDARY CONDITION
:
u
`
C
1
0
D
0
.t
`
C
1
/
INCORPORATE
N
EUMANN BOUNDARY CONDITION
:
u
`
C
1
n
D
2˛
u
n
1
N
1
x
C
D
u
n
C
u
n
C
tf
n
We are now in a position to formulate the complete computational algorithm for our
model problem consisting of the simplified PDE (7.86) and the boundary and initial
conditions (
7.83
)-(
7.85
), see Algorithm
7.3
.
Remark
Thoughtful readers with a lazy attitude may have wondered about a much simpler
way to incorporate the Neumann boundary condition in (7.96). Instead of using a
centered difference, as in (7.94), we could use a one-sided difference,
@x
u
.1; t
`
/
u
n
u
n1
x
@
;
and hence
u
n
u
n1
x
D
N
1
;
which, when solved with respect to
u
n
, yields
u
n
D
u
n1
C
N
1
x :
This updating formula of the boundary value does not involve any fictitious value
(
u
nC1
) outside the boundary, and there is hence no need to combine the discrete
boundary condition with the discrete PDE evaluated at the boundary. Nevertheless,
the one-sided difference is less accurate than the centered difference approxima-
tion we use in the PDE and may therefore decrease the accuracy of the whole
computation.