Information Technology Reference
In-Depth Information
feature in the present ODE example, file writing, is handled in a similar way in the
various languages.
Array creation and processing is particularly efficient in Fortran. First, arrays
are allocated at compile time, with a fixed size (although arrays seemingly have a
dynamic size in subroutines and functions). Second, Fortran 77 compilers have been
developed over five decades to a very sophisticated level with respect to optimizing
(long) loops with array traversal.
Java, Matlab, and Python offer a user-friendly handling of arrays. Arrays can be
created wherever convenient, arrays are efficiently transferred in and out of func-
tions, and arrays are deleted when they are no longer in use. 16 There is, of course,
some efficiency penalty to be paid for having such flexible and easy-to-use arrays.
C CC arrays fall somewhere in between; they are as primitive as in Fortran 77, but
wrapping them in a class opens up the possibility to quickly create much more
user-friendly array objects, and with some significant effort one can implement
arrays that mimic those found in Java, Matlab, and Python. C CC also allows you to
have good (low-level) control of efficiency, which you do not have in Java, Maple,
Matlab, 17 or Python. 18
The convenient array handling and simple plotting capabilities found in Maple,
Matlab, and Python make these languages very attractive for explorative scientific
computing. One should bear in mind, however, that programs written in Fortran or
C/C CC can run much faster.
For exploration of the physical problems and numerical methods covered in
most of this topic, we think both Matlab and Python represent very productive
programming environments. In our opinion, Python has some advantages over
Matlab:
-
The Python programming language is more powerful
-
Several global functions can be placed in a single file (a complete toolbox/module
can be contained in one file)
-
Transferring functions as arguments to functions is simpler
-
Nested, heterogeneous data structures are simple to construct and use
-
Object-oriented programming is more convenient
-
Interfacing C, C CC , and Fortran code is better supported
-
Scalar functions works with vectors to a larger extent (without modifications)
-
The source is free and runs on more platforms
Having said this, we must add that Matlab has a significantly more comprehen-
sive numerical functionality than Python (linear algebra, ODE solvers, optimization,
16 All this functionality can in fact be implemented in Fortran 77, but the language does not support
the functionality, so one has to write lots of low-level code that simulates memory management in
a long fixed-size array, reflecting the computer's memory.
17 In Matlab, most of the array processing functionality takes place in highly optimized Fortran 77
and C functions. Just avoid explicit Matlab loops, see Sect. 6.3.7 .
18 With Python it is very easy to migrate array handling code to Fortran 77, C, or C
CC
to achieve
this low-level control of efficiency.
Search WWH ::




Custom Search