Information Technology Reference
In-Depth Information
7.4.4
How to Verify a Computer Implementation
After having created a program, we need to check that the program is correct. This
is a very demanding task. Ideally, we would like to prove correctness, but this turns
out to be extremely difficult except in very special cases. Instead we have to provide
sufficient evidence that the program works correctly. This means that we establish a
series of test cases and show, for each case, that the results are reasonable. But what
is “reasonable”? The difficulty with this procedure is that our solution procedure
is only approximate, so if we compare numerical results with an exact analytical
solution to the diffusion equation, there will always be differences, i.e., errors. The
question is therefore whether the observed errors are due to approximations or to a
combination of approximations and programming errors. In the forthcoming exam-
ples, we will take a few steps toward providing evidence that a program correctly
implements a solution algorithm for the diffusion equation.
A Trivial Test Case
As a first test of a program, we recommend constructing a case where the solution
is constant in space and time. The reason for this is that many coding errors in
a program can be uncovered by such a simple test. However, this simple test can
also hide many programming errors; so to provide more evidence that the program
works, we need to proceed with more complicated solutions.
To obtain a solution u .x; t / D C ,whereC is a constant, we specify f.x;t/ D 0,
I.x/ D C , D 0 .t / D C ,andD 1 .t / D C . Inserting u D C in the diffusion equation
and the initial and boundary conditions shows that this is indeed a valid solution.
The constant C should not be chosen as 0 or 1, since these values are less likely to
uncover coding errors - forgetting a factor or term can still give a correct u value of
0 or 1. We therefore set C to some “arbitrary value”, say 0:8.
Let us compute u i
values in this case by hand, following Algorithm 7.2 .From
the initial condition we have u i
D C for i D 0;:::;n. The first pass in the for loop
has ` D 0, and we compute u i
from
u i
D C C ˛.C 2C C C/ C 0 D C
for all inner points (i D 1;:::;n 1). At the boundary we set
u 0
u n
D C;
D C:
Repeating the procedure for the next pass in the loop, we find that u i
D C for
i D 0;:::;n, and, in fact, u i
D C for all ` and i values.
Search WWH ::




Custom Search