Information Technology Reference
In-Depth Information
solution method. Each method is expressed as an algorithm and implemented as
a piece of code, normally a function. The code is then a collection of functions
implementing the various algorithms (solution steps) of the whole problem. The
communication between the functions depends on what type of data structures we
use. Therefore, creating numerical software is an interplay between algorithms and
data structures. Typical data structures are scalar variables, arrays, and functions.
A complete algorithm is normally expressed as pseudo code , which is a mixture
of mathematical formulas and instructions known from computer languages. The
purpose is to get an algorithm that easily translates into a computer program. Some
important instructions used in pseudo code (and computer programs) are
1. Assignments; the notation s s C 2 means that we assign the value of the
expression s C 2 to s ,i.e., s is over-written by a new value, 1
2. For loops 2 ; loops controlled by a counter running between two values with a
certain step length,
3. While loops; loops controlled by a boolean condition,
4. Functions 3 ; subprograms taking a set of variables as input (arguments) and
returning a set of variables,
5. Arrays; sequences of numbers, such as u 1 ; u 2 ;:::; u 10 ,
As an example, consider the sum
n X
f.aC ih /;
iD1
where f is a function of a scalar variable, and a and h are constants. We want to
express this sum in a way that translates more or less directly to statements in a
computer program. Normally, a sum is computed by a for loop , using a variable
(here s ) that accumulates the individual contributions f.aC ih / to the sum:
s D 0
for i D 1;:::;n1
s s Cf.aC ih /
end for
Note that the parameters a and h must be pre-computed for this algorithm to work.
After the loop, s equals P n1
iD1
f.aC ih / .
Instead of a for loop, we can use a while loop to implement the sum:
s D 0
i D 1
1 Most programming languages would just use a notation such as s=s+2 , but this notation is
mathematically incorrect, so we prefer to use the left arrow
in our mathematically-oriented
algorithmic notation.
2 Also called do loops (named after the corresponding Fortran construction).
3 Also called subprogram, subroutine, or procedure.
Search WWH ::




Custom Search