Information Technology Reference
In-Depth Information
extensions, but in this simple example it may appear as unnecessary “overhead”
compared to most of the other programming languages we address.
Suppose the shown code segments are located in a file Trapezoidal.java (the
.java extension is required). The programs must first be compiled to bytecode:
unix> javac Trapezoidal.java
Now we can run the code by specifying the name of the class containing the main
program, i.e., the main method:
unix> java Demo
There is unfortunately no built-in method for measuring the CPU time in Java pro-
grams so the easiest way to measure the efficiency is to use the Unix time command
( time java Demo ).
The CPU time ratio relative to the Fortran 77 and C/C CC codes was 2.1, i.e.,
Java ran at approximately half the speed of Fortran 77 and C/C CC in this example.
The test was performed with Java Development Kit 1.1 for Linux. The speed of Java
is likely to improve in future releases.
6.3.5
Matlab
Matlab was originally a user-friendly front end to efficient Fortran 77 libraries for
numerical linear algebra computing. During the 1980s and especially the 1990s the
Matlab environment became more and more user-friendly, and manifested Matlab
as a leading development platform for at least simpler scientific computing appli-
cations. Working with Matlab is not too different from programming in Fortran 77,
but some differences are striking:
-
Statements can be issued in an interactive way, i.e., you can type a command and
immediately view the result.
-
There is no need to declare variables (what we called dynamic typing in a
previous discussion).
-
Matlab has many high-level commands that replace the need for writing detailed
loops.
-
If statements go wrong, Matlab normally issues easy-to-understand error mes-
sages.
-
Matlab offers advanced, integrated visualization. This makes it easy to compute
something and immediately display the results graphically.
These features improve the user's productivity. Matlab is considerably simpler to
work with than programming code segments in Fortran, C, C CC , or Java and calling
up some visualization program.
As a programming language, Matlab is convenient, but somewhat primitive. The
code is interpreted and runs slowly, unless the computations are performed solely
in the built-in Fortran and C libraries. This means that one should avoid long loops
in Matlab and instead try to perform the computations by combining various Mat-
lab commands whose loops are implemented in Fortran or C (more about this in
Search WWH ::




Custom Search