Information Technology Reference
In-Depth Information
Computing u at some given time t k D kt is now a matter of just calling
heun .f; U 0 ;t;k/ . Suppose we want to plot u .t / as a function of t for 0 t T ,
using N points, we can simply implement the following pseudo code:
t D T=N
for i D 0;:::;N
u i heun .f; U 0 ;t;i/ (Algorithm 6.11 )
write .it; u i / to file
end for
The result is typically a two-column file, with t and u values in columns 1 and 2,
respectively, which can be plotted by (probably) any plotting program.
The outlined implementation is very inefficient , yet common among newcomers
to scientific computing. The implementation is very efficient in reducing the need
for computer memory, unfortunately at the significant cost of CPU time: Every time
we call the heun .f; U 0 ;t;i/ function, we recompute what we did in the previous
call, plus compute a single new u value. We should, of course, integrate the dif-
ferential equations up to time T and return all the u 1 ;:::;n N values computed in
Algorithm 6.10 . After the call to the heun function we can dump the returned array
to a file for plotting and data analysis.
Looking more closely at Algorithm 6.10 , we realize that the function evaluation
f. u n / is carried out twice. We should avoid this. A more efficient computational
approach, which should be considered by the reader for implementation, appears
in Algorithm 6.12 . This implementation is flexible; we can call it to advance the
solution one time step at a time, we can compute the complete solution up to the
desired final point of time, or we can call the function several times, computing a
chunk of u n values in each call.
Algorithm 6.12
Optimized Heun's Method.
heun ( f , U 0 , t , N )
u 0 D U 0
for n D 0;:::;N1
v D f. u n /
u nC1 D u n C 2
Πv C f. u n C t v /
end for
return u 0 ; u 1 ;:::; u N
6.2
About Programming Languages
There are hundreds of programming languages. Some of them are well suited for
scientific computing, others are not. We will present the characteristics of the most
popular languages for scientific computing. Our aim is to demonstrate that as soon
 
Search WWH ::




Custom Search