3
$\begingroup$

In our university some Ph.D students for computational methods prefer FORTRAN over MATLAB. I can't understand why? What is the difference between them when are used in computational methods like spectral methods, FEM or BEM? Please tell me which one do you use and why? and what language do you recommend me to learn?

I want to work on computational methods in Fluid Dynamics.

$\endgroup$
6
$\begingroup$

When one uses a low–level programming language, e.g. C++ or FORTRAN, one essentially controls lots of things: how parameters are passed, how data structures are aligned in memory, what is the most efficient way to loop over elements of a big sparse matrix (see cache thrashing) when one multiples it, and so on. In contrast, when one uses high–level software, lots of things are “black box”—it is usually unknown what happens underhood.

Indeed, there is much more to this question, but this is the basic difference. I am not a confident Matlab user, but I can give you an example concerning Wolfram Language: notstandingwith it is very high–level, it uses LAPACK for dense matrix computations (which is a standard software library for this purpose written in FORTRAN). It also relies on Intel MKL which is again written in FORTRAN / C. (So high–level software relies heavily on legacy code.) It also has Compile[] function which may speed things up dramatically.

So these may be reasons why some students of your university prefer FORTRAN: it has low–level features, it is convenient for matrix / vector manipulations, it is pretty old and has a huge legacy (Intel MKL is a good example), it is compilable and fast.

If you look at modern open source FEM software libraries (deal.II, mfem, FEniCS), you will notice that they are developed using C++. FEniCS also has a high–level Python interface which is usually slower than C++’s one.
I believe they tend to use C++ for the reasons I mentioned above.

As for me, I use C++ for large computations. I also use Mathematica for symbolic computations (which is extremely useful) or if I want to code something fast. So my suggestion would be this: learn at least one high–level and at least one low–level language.

$\endgroup$
  • 1
    $\begingroup$ Another angle on using C++ in computational science, e.g. for computational fluid dynamics, is that you can bake fundamentals right into your data structures, thus separating the low-level stuff (numerics) from the high-level stuff (modelling physics). One example for such a code in C++ is OpenFOAM. $\endgroup$ – Dohn Joe Oct 10 at 7:33
3
$\begingroup$

This question can be considered opinion based, but can be useful for who starts in the field. In the answer I try to do not use personal opinion but suggest some criteria of choice

Well to begin Fortran is program language with a long story, it was born to do computations. Matlab is more like to an environment, it is built over (you can read make in) Fortran.

Matlab is implemented to provide a user friendly environment in which to develop numerical code (in particular for handling matrices) quickly and simplicity. It comes with many features and methods already available to be immediately productive. Obviously, these advantages are offset by some compromises, such as the speed of execution (here I am a bit 'simplifying, but I think the idea is quite clear).

For these reasons Matlab is mainly directed to the development prototype, abusing a computer terminology is not for production use. Conversely Fortran is a compiled language in which the development of the code is slower, but has some advantage such as performance.

Thus an answer to the question is depend. Depends on what? Your goals. I try to explain.

You can do CFD with Matlab. In this case I expect that your work is more focused on the development of new numerical methods and not on the application itself. This mainly because of the ease of development (read implementation) new ideas / algorithms and because would you use problems of "small" size in which the appearance of computations performance is less important.

But if your interest is the simulation results, perhaps using real problems, then you most likely are better Fortran or Domain specific languages/programs (commercial or otherwise).

$\endgroup$
3
$\begingroup$

In general, you will be much more productive writing software in a higher-level language (e.g MATLAB) that has features useful in describing problems in your particular domain (e.g. matrices in computational science). Often much more time is spent writing the software rather than acutally running it so reducing programming time by using the right higher level language as opposed to reducing runtime by using a lower-level language is the right tradeoff.

So your question is not so much MATLAB vs FORTRAN as it is high-level versus low-level languages. Even the assumption that I made about a high-level language leading to slower running code is not necessarily true. One of the goals of the Julia programming language project is to challenge that assumption.

To get a much better understanding of this low-level versus high-level language comparison, I strongly suggest taking a look at some of the documents written by the Julia developers (e.g. Julia: A Fresh Approach to Numerical Computing)

Understanding these broader issues will allow you to make an informed decision about the specific question, MATLAB versus FORTRAN.

$\endgroup$
  • $\begingroup$ I don't necessarily agree with this. In scientific computing there are many fields in which to make meaningful progress and get results you need to show a somewhat realistic case, and matlab (or any higher level language of choice) wont run your code fast enough to be feasible. Furthermore, the "black box"-ness of matlab (or any higher level language) can be a problem for more intense development. $\endgroup$ – EMP Oct 8 at 14:32
2
$\begingroup$

It is interesting that people nowadays Fortran is a low-level language. When I was in school, Fortran was a high-level language and the low-level languages were machine language, assembler, and macros. Those does bit, byte, word manipulations at the accumulator and memory level. I would say MATLAB is a higher-level language made up of libraries of routines written in high-level languages with an over arching interpretive calling program.

$\endgroup$
1
$\begingroup$

There are already very good answers, and I want to add only two aspects:

Vendor Lock:

If you choose Matlab or similar Packages (Mathematica etc.), you chain yourself to that vendor. Many universities pay the fees to have these programs available for their students and researchers. Some may not, however. If you develop whatever you are doing in a proprietary package, then only those people who can afford to use that software will be able to benefit from your work. The only way to do the very important step of verifying or falsifying your work by a third party is only possible if this party has matlab!

Contrary to this, programming languages are more free. If you do good research, and find some groundbreaking insights, the verification/falsification can be done as easily as giving your code a free licence, and uploading it somewhere.

Transparency:

Imagine down the road someone approaches you at a conference and claims that your results are wrong. They can not be right! There must be some mistake. You could, of course, show that person what you have done in matlab and you can prove to him that what you did was reasonable. The results persist to be off! Then the two of you will stare at the huge blackbox of software that is matlab, and will not be able to figure out what the hell went wrong.

Contrary to this, if you limit yourself to open source languages and compilers, then you at least have a chance of following the rabbit hole all the way to the bottom if there is some bug or mistake.

Disclaimber: I do think that programs like Matlab have their place in rapid prototyping. If you want to check out on an idea and you have only one week to do it, then Matlab may be a good tool afterall!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.