Scientific programming

for non-programmers

by Nikolai V. Shokhirev

Up ABC tutorials

Up: Scientific programming
Next: Numerical Methods

Introduction

There are some fields (e.g. science, engineering, education) where the development of ideas, concepts, models and methods is more time-consuming than the accompanying computations. In such areas tools like Mathematica (http://www.wolfram.com), MATLAB (http://www.mathworks.com) and Maple (http://www.maplesoft.com) are widely used. 

There are also several free tools:

MAXIMA is a fairly complete computer algebra system. (http://sourceforge.net/projects/maxima , http://www.gnu.org/software/maxima/). Symaxx/2 is a graphical front-end for the Maxima computer algebra system (http://symaxx.sourceforge.net/). See also wxMaxima, a cross platform GUI for the computer algebra system maxima based on wxWidgets.

Clones of MATLAB: GNU Octave is a high-level language, primarily intended for numerical computations. (http://www.octave.org/). Scilab is a scientific software package for numerical computations (http://scilabsoft.inria.fr/). Freemat is a matrix-oriented development environment for engineering and scientific applications (http://sourceforge.net/projects/freemat/).

Advantages of tools for doing symbolic and/or numeric calculations:
1. Abundance of built-in methods and features
2. Flexibility with a variety of supporting techniques 
3. Scripting and programming abilities for further enhancement 

Drawbacks:
1. Necessary to learn a lot of features
2. Restriction of flexibility by predefined approaches
3. Necessary to learn tool-specific programming methods or
4. Use of  third party add-ins

The alternative approach is to use high-level programming languages. Note that, in such areas programming is usually only a tool. This approach has its advantages and disadvantages as well.

Advantages:
1. Relatively small number of language elements
2. Flexibility is (almost) unlimited
3. Potential high efficiency
4. Self-sufficiency
5. Freedom!

Disadvantages:
1. Necessary to write programs from scratch
2. Relatively low productivity (for non-professional programmers)

Numerous libraries and packages help to overcome the disadvantages of the programming approach. Later I will introduce my Pascal and C++ libraries. I have been using them for several years.  

To whom this tutorial is addressed

Platform/Language/Tool selection

Platforms

The most popular platforms are

  1. Windows
  2. Linux (and the other Unix-like systems)
  3. Java (this is a language and a platform itself)
  4. .Net-platform

Windows software dominates in the areas of word, data, and image processing (Mac-programming is out of the scope of this tutorial). To be realistic, we should focus on Windows with the possibility of migrating to Linux.

Languages

Visual Basic (VB) is among the most popular programming languages in the world. It has an advanced development environment with a component-based Graphical User Interface (GUI) design. However VB is not designed for numeric calculations and lacks good numeric libraries. VB.Net is improved object-oriented version.   

All classical scientific algorithms were developed in the 60's in Algol and Fortran (see e.g. [1, 2]). Fortran was designed specifically for numerical calculations (ForTran = Formula Translator). Later, it evolved towards Object-Oriented Programming (OOP). Fortran still beats all languages at all platforms in efficiency. Unfortunately, Fortran was completely eliminated from computer science courses and now even many engineers (!) do not know it. Despite all this, Fortran is still used and new compilers are developed [3].

Later the algorithms were rewritten and further developed in many other languages. In particular, a lot of numerical libraries were developed in C++ and Java.

Java is a pure OOP cross-platform language, but the development (specially GUI) is a tough task for non-professional programmers (see, however, Borland's JBuilder, currently Codegear's JBuilder).

C++ was the first successful OOP language. But actually, it is an OO extension of the low-level c-language. C++ is clamed to be for universal programming. However, programming in any particular area is not an easy task [4] (for a non-professional programmer, see the sub-title above).  

Microsoft's C# represents the latest generation of object oriented languages. It is a part of well thought out and elaborated .Net framework. This dramatically increases development efficiency, including GUI, Databases and Web. This platform, including C#, is porting to Linux, Solaris, Mac OS X,  and Unix as a part of the  project Mono.

Scientific/engineering programming does not require a lot of object-oriented programming (OOP). Pure procedural languages (e.g. C and Fortran) work just fine. In my opinion the choice of language is not important for our purpose (the quick sort will beat the bubble sort in any language). More important are development and debugging tools, compilers, text and graphic support, and the performance to price ratio. 

Development tools

Microsoft Visual Studio has excellent visual design support both for VB.Net and C#. However Visual C++ IDE (Integrated Development Environment) is far behind of the first two. Microsoft Visual studio comes with a free Express editions for VB.Net, C# and C++ (versions 2005 is still available). 

Borland products (Delphi, C++Builder, Kylix, C#Builder, JBuilder) have a unique combination of features. They traditionally are very efficient and user friendly. They all extremely simplify the graphical user interface development (Rapid Application Development - RAD). Open, personal and academic editions are free or relatively  cheap. There are also free Turbo Explorer editions for Delphi (Object Pascal), Delphi.Net, C# and C++ (http://www.turboexplorer.com/ see also http://www.codegear.com/products/turbo). Object Pascal is a high-level language with the object model similar to Java. Borland's  Pascal compiler is extremely fast and produces very efficient code.

The integrated development environments (IDE) for Object Pascal and C++ are available both for Windows and Linux. Unfortunately Borland discontinued Kylix, its Pascal and C++ IDE for Linux. The rest of products are now developed by Code Gear, Borland's Tool Division.

Also worth mentioning is Lazarus, a free Delphi-like IDE for Free (Object) Pascal. This is a real RAD IDE with code completion and other advanced features. It is currently available for Windows and Linux, Mac and some other platforms. This is an open-source (free) tool.

Another nice (and free) development tool for the .Net platform (C# and VB.Net) is #develop .C# was developed by Anders Hejlsberg [5], the author of Turbo Pascal and the chief architect of Delphi.

DevCpp (DevC++) and DevPas are the free tools from Bloodshed Software for C++ and Free Pascal. They have full-featured IDEs, although they are not RAD tools. However, there is wxDev-C++, an extension of Dev-C++ for building GUI with wxWidgets. DevCpp uses GNU g++ compiler on MinGW.

Links to the comparison of some discussed visual tools [6-12].

References

  1.  J. H. Wilkinson, C. Reinsch, Handbook for Automatic Computation, Volume II, Linear Algebra, Springer-Verlag, New York, Heidelberg, Berlin, 1971
  2. George E. Forsythe, Mike A. Malcolm, and Cleve B. Moler, Computer Methods for Mathematical Computations, Englewood Cliffs, N.J.: Prentice Hall, 1977.
  3. G95 - a free Fortran 95 compiler available for multiple CPU architectures and operating systems http://www.g95.org/ .
  4. Sean Barrett. Why C++ Sucks, http://nothings.org/computer/cpp.html 
  5. Anders Hejlsberg http://en.wikipedia.org/wiki/Anders_Hejlsberg 
  6. Marco Cant. Comparing OOP Languages: Java, C++, Object Pascal, http://www.marcocantu.com/papers/ooplang.htm 
  7. Dan Miser. Delphi and C# comparison, http://distribucon.com/blog/archive/2004/04/26/178.aspx 
  8. Ernesto De Spirito. A comparison between Delphi and Visual Basic, http://www.latiumsoftware.com/en/articles/00010.php 
  9. Steve Scott. Microsoft Visual Studio .NET: A View From Across The Fence, http://www.thedelphimagazine.com/samples/1212/1212.htm 
  10. C++ Builder vs. Visual C++, http://boumchalak.net/content/view/98/2/ 
  11. Microsoft Visual C++ vs. Borland C++Builder. http://www.slim.sytes.net/~kztakeda/comp/bcb/vc_bcb_e.html 
  12. VC++ vs. C++Builder, http://www.devhood.com/messages/message_view-2.aspx?thread_id=31628  

Links

Downloads

Up ABC tutorials

Up: Scientific programming
Next: Numerical Methods

Home | Resumé |  Shokhirev.com |  Computing |  Links Publications

©Nikolai V. Shokhirev, 2004-2008