Information Technology Reference
In-Depth Information
types, but no way to create user-defined types. Having said this, we should add that
languages with a rich collection of built-in data types and dynamic typing, such
as Maple and Python, often offer the ability to create heterogeneous lists or hash
structures that replace the traditional use of classes in C CC and Java.
A class can be viewed as a definition of a new type of variable. To create variables
of this type, one creates objects of the class. The program will therefore work with
objects in addition to variables of built-in types. Programming with objects is a bit
different from programming with fundamental built-in types, such as real, integer,
and string. In the latter case, collections of primitive variables are shuffled in and out
of functions (subprograms) and the software is organized as a library of functions.
With classes, the functions are often built into the classes, and the software is a
collection of classes (i.e. data types) instead of a function library.
The real power of class-based programming comes into play when classes can
be related to each other in a kind of family tree, where children classes inherit func-
tionality and data structures from parent classes. Although the implementational
and functional details can differ between members in such a tree of classes, one can
often hide these differing details and work solely with the topmost parent class. This
is called object-oriented programming and constitutes a very important program-
ming technique in computer science. The Java language is very tightly connected
to object-oriented programming. Object-oriented programming is highly valuable
in scientific computing, especially for administrating large and complicated codes,
but the traditionally popular languages Fortran and C do not support this style of
programming.
6.3
The Trapezoidal Rule in Different Languages
On the following pages we shall give a glimpse of some widely used programming
languages: Fortran 77, C, C CC , Java, Matlab, Maple, and Python. All three lan-
guages are popular in scientific computing communities. The exposition is strongly
example-oriented. The simple trapezoidal rule from Algorithm 6.2 on page 201 is
implemented in each of the mentioned languages. The code segments are briefly
explained and accompanied by some comments related to topics such as static typ-
ing and computational efficiency. In Sect. 6.4 we shall implement Heun's method
from Algorithm 6.12 in the aforementioned computer languages and thereby learn
more about arrays and file handling in different languages. When solving ODEs,
we also need to display the solution graphically, and this is shown by plotting the
solution using Gnuplot and Matlab.
6.3.1
Code Structure
The main structure of the code for performing numerical integration with the aid
of the trapezoidal rule will be quite independent of the programming tool being
Search WWH ::




Custom Search