Information Technology Reference
In-Depth Information
6.1.6
Ordinary Differential Equations
Writing algorithms in mathematical pseudo code represents a considerable portion
of the software development work, at least for the (quite simple) type of problems
we deal with in the present topic. Before looking at the translation of pseudo code
to specific computer languages it can therefore be instructive to go through another
example on pseudo code development. Consider an ODE,
u 0 .t / D f. u /;
u .0/ D U 0 ;
solved approximately by Heun's method:
u nC1 D u n C t
2
Œf . u n / Cf. u n C tf . u n // :
(6.13)
Here, u n is an approximation to the exact solution evaluated at the time point nt .
A direct translation of (6.13) to an algorithmic form leads to Algorithm 6.10 .
Algorithm 6.10
Heun's Method.
heun ( f , U 0 , t , N )
u 0 D U 0
for n D 0;:::;N1
u nC1 D u n C 2
Œf . u n /C f. u n C tf . u n //
end for
return u N
We have previously mentioned that mathematical symbols with indices normally
translate to arrays in a program, which in the present case means that we store
u 1 ; u 2 ;:::; u N . An optimization-oriented person who is very concerned about reduc-
ing computer memory might claim that to compute the return value u N , we can get
away with storing only one u value at a time, as expressed in Algorithm 6.10 .
Algorithm 6.11
Memory-Optimized Heun's Method.
heun ( f , U 0 , t , N )
u D U 0
for n D 0;:::;N1
u u C 2
Œf . u / C f. u C tf . u //
end for
return u
 
Search WWH ::




Custom Search