Is Matlab (vs. C/FORTRAN) a respectable language for a professional mathematical researcher of the 21st century?

12,447

Solution 1

I work with a team of professional research geophysicists though I'm more of a numerical software engineer myself. I think that if your work is numerical mathematics then Matlab is very suitable, especially so since you are already skilled in its use.

You might write faster programs if you picked up C or Fortran, though perhaps not as much faster as you would hope since Matlab uses, for a lot of its numerical routines, the same BLAS (etc) libraries as you would if you were writing in C or Fortran. But from my working experience my colleagues find the ability to write programs more quickly much more important than writing quicker programs. They generate a lot of ideas which, upon reflection, they later reject. The added speed of development that Matlab gives over and above C and Fortran means that they go through the whole cycle (which generally includes visualisation of results) a lot more quickly and do it more often, so doing more science by some crude measure.

(As an aside: one of the jobs I get is to turn some of the Matlab code that is not rejected into Fortran programs for execution on the company's large clusters. But that's what happens to some of our codes when the initial research is complete and we want to deploy them for production.)

I'd also point out that Matlab has good parallel computing capabilities (if you can afford them) through its Parallel Compute Toolbox, which will probably be of interest as your problems become larger and you realise that you are underusing some of your cores, gosh it's even got integration with GPU computing in the latest release.

In a nutshell I'd suggest that staying with Matlab will allow you to focus on your mathematical research and not divert your attention to wrestling with a new toolset. Especially so since you do not suggest that Matlab is inadequate for your expected needs.

Solution 2

If you are mainly involved in prototyping algorithms that involve simple data structures, matlab is a great choice. The workflow of many academics working in computational fields is: develop a new algorithm, check that it works in matlab, then you write your paper, and you're done. If this is all you wish to do, stick with what you know (matlab).

If you want to do more than that... Well Fortran and C/C++ are not directly comparable to Matlab because there is just no reason to use a compiled language unless performance is critical. Python, on the other hand, has a similar feature set to matlab, in addition to being a free full programming language with a vibrant online community. The downsides to switching to python are surprisingly negligible, and the upsides are huge. I miss some of Matlab's array handling syntax, as Numpy (python's module for array manipulation) has a few quirks, but that's about it. I switched from matlab to Python recently, and I don't plan on going back. Matlab seemed to make me write code in the worst possible way. My python code is much cleaner, more modular, and easier to read. Also, the Sphinx documentation system is terrific.

In short, consider python if:

  • You are going to need to maintain a large codebase
  • You want to make your project open source and have others contribute
  • You want to make your code available to people without a matlab license
  • You want to write your own custom data structures other than arrays (trees, graphs, ...)
  • You need to implement non-numeric code (search local directories, download from urls, find local files using regular expressions, text processing)
  • You want to generate awesome documentation easily and effectively
  • You don't want to spend cash on a matlab license

Here's a link arguing for python over matlab for scientific research: http://www.stat.washington.edu/~hoytak/blog/whypython.html

Here's a self indulgent link showing the amazing potential of python Sphinx to auto-generate beautiful online documentation that seamlessly integrates mathematical derivations and actual source code: http://pythonhosted.org/fit_neuron/overview.html

Python seems poised to become THE standard in scientific computing, so it's definitely worth learning.

Solution 3

Speaking as someone who moves between academia and industry in an engineering field, the only reason I don't use Matlab more is because of the cost. If you and all the people you want to give code to have Matlab licenses then there's no reason to switch.

If you find that parts of your code need to be optimised, you can rewrite just those bits in a lower-level language and call them from your Matlab program. Switching languages for performance reasons is a case of premature optimisation, in my opinion. I solve computation-intensive problems in an iterative process:

  1. Put together a solution in the quickest and most straightforward way first, which in your case means using the language you know best.
  2. Run it with a limited data set using a profiler and figure out where the bottlenecks are.
  3. Fix the worst bottleneck, using any of the following methods: a) Change the algorithm, b) optimise using the features of the current development environment, c) rewrite that bit of code in something that executes faster for that particular problem.
  4. Go back to 2. until your run time/development time equation reaches whatever threshold you're comfortable with (or, if you're a graduate student, until your supervisor shouts at you to STOP FIDDLING WITH THE BLOODY THING AND JUST RUN IT ALREADY).

In other words, don't stress about performance until it becomes a problem, especially if you're writing code for your own use.

Solution 4

Well I'm more a C++/Java programmer than a Matlab one, although I have used Matlab, but I think that for mathematical research, Matlab is rather well suited. Research is something that involves a lot of experimentation, and C++ is a dire language in which to do experimentation. Matlab makes it very easy to test things quickly, find out which ones work and which don't, and move on. You can always code up your solutions in another language once you know what you want to do, assuming that the Matlab version is too slow (from the limited amount I've seen of it, sometimes it is, sometimes it isn't).

Bottom line: you might not want to use Matlab for everything (the phrase "if all you have is a hammer, everything looks like a nail" springs to mind), but it's certainly a good language for the specific task of mathematical research.

Solution 5

I would also consider the software Mathematica which is great for some of the needs mathematicians have

Share:
12,447

Related videos on Youtube

mr matlab
Author by

mr matlab

Updated on August 25, 2020

Comments

  • mr matlab
    mr matlab over 3 years

    I am a die hard user of matlab, mostly because this is what I learned first and I have not encountered a problem with a significant enough difference to switch. I come from numerical optimization/linear algebra, where I have performed optimization and eigenvalue computations in millions of degrees of freedom. Recently, I have entered the realm of randomness, where I was originally under the impression I would be forced to change. But, after optimizing code, and carefully initializing the seed to the random number generator, I am able to do the same Monte Carlo tasks as my contemporaries in roughly the same time. My understanding has been that base-level 'if' statements, etc., are significantly slower in matlab. However, if there are significant computations within each loop which can be vectorized, I'm not convinced C would be better. And, anyway, matlab seems to do just fine, in the sense that my upper bound is no less than any other professional (and in many cases, seems to be more). I have a feeling that I will get lots of responses from pro-C people here, who have written off matlab long ago as some trivial toy language. I am a professional researcher and contend that matlab is competitive for the highest level computationally intensive mathematical programming. Am I wrong ? Do I need to consider changing to a lower-level language, such as C/FORTRAN ? Why or why not ? Are there others like me ? Thanks alot! Cheers

    • SimonJ
      SimonJ over 13 years
      +1, interesting question. I'm not qualified to give a proper answer, but had similar concerns a few years back as a computational physics student. At the time our department had many die-hard Fortran/C programmers who didn't recognise much benefit in higher-level tools but I'd hope things have changed, with ease of parallelisation and agility increasingly more important than raw single-core execution speed.
    • mtrw
      mtrw over 13 years
  • High Performance Mark
    High Performance Mark over 13 years
    But for numeric work, I'm not sure I'd advise OP to switch to Mathematica.
  • Jonas
    Jonas over 13 years
    +1 for "it's more important to write programs quickly than to write quick programs".
  • Stuart Golodetz
    Stuart Golodetz over 13 years
    @Jonas: +1 for research purposes, where that's often true -- it's not the case more generally though. A lot of systems have real-time constraints. Even your word processor does -- I wouldn't prefer to have my word processor delivered sooner if it took 5 minutes to type each character.
  • Jonas
    Jonas over 13 years
    @Stuart Golodetz: Actually, even for research purposes, anytime the user interacts directly with the system, it has to be fast. However, once the user has hit "run", it's ok if it takes a while, as long as it works at all (and I have just had a discussion yesterday with a colleague where they've been struggling with a problem for which there seems to be no working algorithm at the moment).

Related