Environmental Engineering Reference
In-Depth Information
variables, we plot the analytical solution, as given by ( 21.3 ). Then the numerical
solutions are computed as described. In the outer loop (with counter variable i ), in
each iteration we halfen the timestep. In the inner loop (with counter variable j ) the
numerical solution is computed. The numerical solutions are plotted after calcula-
tion, in the outer loop. Here we use only four different timesteps, i.e. we refine three
times, in order to see the differences from one numerical solution to the next in a
single plot.
% numerics demonstration (for decay equation)
Tmax = 1;
lambda = 2;
c0 = 1;
marker='sod.';
% plot analytical solution
plot (Tmax*[0:.01:1],c0*exp(-lambda*(Tmax*[0:.01:1])),'-r');
hold on
% compute and plot numerical solutions
deltat = .5*Tmax;
for i = 1:4
f = 1-lambda*deltat;
c(1) = c0;
for j = 2:2^i+1
c(j)=c(j-1)*f;
end
plot (linspace(0,Tmax,2^i+1),c,['-' marker(i)]);
deltat=deltat/2;
end
legend ('analytical',['\Delta' 't=.5'],['\Delta' 't=.25'],['\Delta'
't=.125'],['\Delta' 't=.0625'])
The complete code is included in the accompanying software under the name
'numdemo.m'
In the following figure we show the results of the numerical method for c 0 ¼
1,
l ¼
1 is 0.1353. The
unmarked graph depicts the analytical solution. If we use the timestep
2 and the time interval
t 2½
0
;
1
. The solution at
t ¼
D t ¼
1/
2 we obtain c (1)
0, which is a very bad approximation. But we can easily see that
we obtain much better results if we use smaller values for
¼
D t (Fig. 21.1 ).
The demonstration shows clearly that the solution is better approximated for
smaller timesteps. In general we may use the term discretization . Here the time
period is discretized into smaller peaces, the timesteps: the smaller the timestep, the
finer the discretization; and the better results can be expected.
Mathematicians say that the numerical solutions converge towards the wanted
solution with refinement of the discretization. All numerical solutions are
approximations for the 'real' solution. For practical purposes it is always sufficient
to obtain an approximate solution. It depends very much on the problem which
degree of approximation is wanted, and on the programmer as well.
There is a simple procedure, which is usually applied in order to check the accuracy
of the solution. If the modeller uses different discretizations, she/he can check the
change from the finest to the previous discretization. If the change is lower than the
wanted accuracy, the programmer is usually satisfied. It is not strictly guaranteed that
the required accuracy is reached, but the described criterion to end the discretization
refinement usually delivers an approximation that deviates from the real solution by
Search WWH ::




Custom Search