« previous next»

1.2    Why Fortran?

Probably many of you are wondering why you need to learn Fortran when we have numerical computing environments like MATLAB and seemingly more popular programming languages like C, C++ or Java. With its improved performance over Fortran 77 in the areas of numerical robustness, data parallelism, data abstraction, and functional programming, Fortran 90/95 remains the language of choice for computational science. C leads only in the area of object-oriented programming, an issue that Fortran 2003/08 hopes to address. A comparison of Fortran to MATLAB, however, is much trickier.

MATLAB is a high-level technical computing language and interactive environment for algorithm development, data visualization, data analysis, and numeric computation. Using the ever expanding repertory of MATLAB commands and functions, you can develop a code to solve many engineering problems faster than with a traditional programming language like Fortran. However, a compiled language like FORTRAN may offer significant speed advantage when your program needs a lot of CPU time to run and you need to execute it many times for different sets of data.

Every MATLAB command in a script must be interpreted and converted to machine instructions at run time. This can add a significant overhead to the execution time if that particular operation has not been compiled a priori by coding it in a language like C or Fortran. In many instances, therefore, an optimized Fortran code will outperform a MATLAB script that performs the same computations.

Because Fortran has been the main programming language for scientific and engineering computations for a long time, you will find that many important algorithms have already been coded in optimized Fortran and are available on the Internet. This eliminates the need to spend a lot of time writing code for algorithms that may not yet be available in MATLAB or in one of its many toolboxes.

When it comes to a question of MATLAB vs. Fortran, follow this simple rule at first:

As you become more proficient in the use of MATLAB and Fortran, you can have the best of both worlds by combining these tools:

 

« previous next»