Information Technology Reference
In-Depth Information
Comparing with an Exact Solution
Exact solutions to PDEs are, in general, hard to find. However, for the diffusion
equation some typical solutions are well known. Inserting
u .x; t / D e 2 t sin.x/
(7.97)
in the governing equation shows that this is a solution if f D 0. We can then adjust
I , D 0 ,andD 1
such that (7.97) is the solution, i.e.,
I.x/ D sin.x/;
D 0 .t / D 0;
D 1 .t / D 0:
Running a program that implements Algorithm 7.2 should result in a numerical
solution that is close to the exact solution (7.97), but how close? We know that our
numerical approximations used to derive Algorithm 7.2 contain errors, so how can
we distinguish between a numerical approximation error and a programming error?
This is a really difficult question, which indicates how hard it can be to check if
simulation programs are free of programming errors. A good approach to answering
the question goes as follows.
One can mathematically show that the error E implied by the scheme in
Algorithm 7.2 is of the form
E D C 1 x 2 C C 2 t :
(7.98)
For a given ˛ value we can replace t by ˛x 2 :
E D C 3 x 2 ;
C 3 D C 1 C C 2 ˛:
(7.99)
This means that if we halve the grid spacing x, the error should be reduced by a
factor of four. This is something we can test to provide evidence that the program is
working correctly. It appears that this is one of the best test methods we can apply.
Let u .x; t / be the exact solution and Q u the corresponding numerical solution. The
error can be defined as
s Z 1
. u u / 2 dx :
E D
(7.100)
0
Since Q u is only known at the grid points, we approximate the integral by the
trapezoidal rule:
E x 1
!! 1=2
/ 2 C n X
iD1
/ 2 C 1
2 . u .0; t ` / u 0
2 . u .1; t ` / u n
. u .x i ;t ` / u i
/ 2
:
(7.101)
With the exact solution (7.97), we can compute E corresponding to four grid res-
olutions: x D 0:1; 0:05; 0:025; 0:0125.SinceE=x 2 should be a constant (called
 
Search WWH ::




Custom Search