8
$\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$

7 Answers 7

11
$\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$
2
  • 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, 2019 at 7:33
  • $\begingroup$ "modern open source" does not need to be "better" than "old open source" or "old closed source" btw. $\endgroup$
    – user24074
    Aug 21, 2023 at 8:22
8
$\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$
1
  • 4
    $\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, 2019 at 14:32
4
$\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$
2
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$
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$
0
$\begingroup$

Why compare Fortran with Matlab. Matlab and Mathematica are more similar to each other than Fortran. Fortran is lower level language in comparison to Matlab and Mathematica. Matlab in my opinion is a bit on the pricey end.

$\endgroup$
-4
$\begingroup$

Let me add that I've just completed a graduate certificate in Mathematics. All the math courses at NCSU teach using mostly MATLAB. I work as an engineer at LGS Labs, which used to be LGS Innovations & came from Bell Labs, has 100's of engineers that use MATLAB for prototype development of signal processing code, wireless communications modeling, and so forth. I've never heard of any of them developing new code using anything other than MATLAB. One thing missed in previous comments, is that MATLAB has many built-in tools that make visualization, debugging, plotting, etc. of your code very fast and easy. For example, you can quickly and easily view any of your variables with just the click of a mouse, including quite large matrices. MATLAB also comes with a wide variety of licenses for companies willing to pay. For example I have one, LTE Toolbox, that costs about $11,000 . It can create any type of LTE signal, as I/Q digital data, you want down to every last detail. It would take > one to two years of man hours to figure everything out that this toolbox can do. MATLAB was built for matrix computations, and while yes it is slower than C++/Fortran compiled code, there is a powerful way to make it really fast called vectorization, which is easy to learn. These are a single line of code, that can manipulate data in many ways in giant arrays/matrices. It also has TONS of built-in commands in the basic package; for example matrix tools like SVD, eigenvalue/eigenvector computation functions, ODE solvers, iterative matrix solvers like GMRES, other solvers, various factorizations, etc. etc. It's probably still slower than compiled code, but I would bet not that much when programmed for speed. I can run 2D matrix sizes into the millions of rows on it. It can even store filesizes >2GB (matfile version 7.3), and can open parts of that file without loading the entire file into memory. So in a nutshell, MATLAB is awesome, whether it's just the core MATLAB, or you have advanced licenses. In addition, you can even create C++ compiled executable code and link it to MATLAB. This is how their built-in functions work already. You can access ALL the helpfiles on the Mathworks website for ALL functions, even for ALL their commercial licenses! So you can judge for yourself.

$\endgroup$
2
  • 6
    $\begingroup$ Everything you say about its capabilites is correct. But is there anything your institution could do if Mathworks adds another zero to that licence cost? Do you think research institutions around the world have those 11,000$ to enable their researchers to reproduce your results? What you describe is quite the definition of vendor lock-in. $\endgroup$
    – MPIchael
    Nov 4, 2020 at 9:25
  • $\begingroup$ Yes but I'm pretty sure they can't just 'add another zero' without the demand going kaput. At NCSU for example, they allow students to use alternative high level programming languages. NCSU provides maple also, so I'm sure that helps keep the Matlab cost down, plus NCSU has huge purchasing power. I'm just sharing my own experience with it - I'm very impressed with the amount of built-in functions, even with the basic license. Everybody has to make money, and Mathworks is no exception, but the quality is high. $\endgroup$
    – Vince
    Nov 9, 2020 at 18:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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