14 ms·
Matlab vs. Julia vs. Python
- w_t_payne 7y agoI've a lot of experience with both MATLAB and Python. I find Python to be the better designed language, with fewer rough edges. But MATLAB still promotes and encourages the most productive approach to programming, one that NumPy just falls short of.
- dagw 7y agoFor exploratory work MATLAB and the MATLAB IDE are pretty good and shorter scripts are fine. However once you start trying to write actual programs and pass 1-2 kLOC or so, MATLAB just gets more and more painful.
- ChrisRackauckas 7y agoAnd "MATLAB packages" are especially painful. The fact that you "install packages" by adding folders to the path is somewhat insane, especially since that is somewhat of a silent global change. I think the hardest thing to do with MATLAB is get someone else's scripts running, because it's always like "oh I forgot to give you my special plot function which I keep in this folder, but requires other things, so just add this whole thing to your global state, but it's incompatible with XXX since I use a function named A". Remembering those incidents makes me shed a tear... while Python and Julia allow you to import without sending every internal name and you're done. And in Python and Julia, people add continuous integration tests to packages.
- makmanalp 7y agoI like to say that Matlab was designed by applied mathematicians who don't want to care about software engineering, and python+numpy+scipy was designed by software engineers who don't want to care about applied mathematics :P I don't know that that's strictly true but it gives you a general idea for why things are the way they are.
- rightbyte 7y agoSomehow it's nice to have a global namespace so I dont have to remember which libs have "plot()" or "sind()". Nothing beats Matlab/Gnu Octave for me when I just want to make some quick calculations.
- ddragon 7y agoJulia "default" behavior (the 'using' keyword) is also importing everything (that is exported on the selected module) to the global namespace, using multiple dispatch to safely assign the optimal implementation of each function for each argument set without clashing. It's not unusual in Julia to have one function with more than a hundred implementations, and the user doesn't need to care which one will be chosen. Though you can also use 'import' to keep the namespaces separate.
- ChrisRackauckas 7y agoIt's not really a default though. You have to always choose to do `using` instead of `import`. A lot of people choose `using`, because it's generally more safe than something like MATLAB or Python because of multiple dispatch, but there's nothing in the language that actually defaults to `using` other than the convention of some people.
- philipov 7y agoWhen you say numpy falls short, do you also include pandas?
- newen 7y agoTry using R's data.table and then use pandas. Pandas is just awful to use in comparison.
- bllguo 7y agoI'm of the same mind, and have been surprised for a long time that this isn't commonly said. dplyr/tidyverse also suits my thinking process around working with data much better than pandas, which is by far the worst of the lot. h2o.ai has been working on data.table for python (https://github.com/h2oai/datatable https://github.com/h2oai/datatable). Hope it matures quickly
- wvlia5 7y agoRun this python jewel: exec(''.join(chr(int(''.join(str(ord(i)-8203)for i in c),2))for c in ' '.split(' ')))
- usgroup 7y ago"MATLAB is the BMW sedan of the scientific computing world. It’s expensive, and that’s before you start talking about accessories (toolboxes). You’re paying for a rock-solid, smooth performance and service..." mmmmhmmmm...
- hprotagonist 7y agoThis [Julia] is the first language I’ve used that goes beyond ASCII. Python 3 has supported unicode variable names for 12 years. Not all of unicode is permitted, but all the useful bits are.
- 3JPLW 7y agoSubscripts and superscripts are probably some of my most-used unicode identifiers. Supported in Julia but not Python 3. In [1]: α₁ = 1 File "<ipython-input-1-3c2973844bb9>", line 1 α₁ = 1 ^ SyntaxError: invalid character in identifier
- diminoten 7y agoInline? I dunno, shouldn't the thinking be separated from the showing? IOW, of course python can display sub/superscript, but using it in the code doesn't feel necessary.
- 3JPLW 7y agoYes, absolutely "inline" as identifiers in your code. So many algorithms use subscript or superscript notations, and it's so nice to be able to use names like vₓ or H₀ or χ² or Aᵀ directly.
- jacobolus 7y agoNice as long as you are only reading a paper printout of the code and never have to write or edit it yourself, since your keyboard is never going to be set up for typing someone else’s choice of weird symbols.
- 3JPLW 7y agoThat's also not true. Julia itself defines the tab completions for all these characters — and they'll be very familiar to you if you've ever used latex. They're just a tab away in every editor worth its salt. α₁ \alpha<TAB>\_1<TAB> vₓ v\_x<TAB> H₀ H\_0<TAB> χ² \chi<TAB>\^2<TAB> Aᵀ A\^T<TAB> When I went to do the python demo above, IPython also tab-completed the `\alpha` above... but to get the ₁ the quickest and easiest way for me to get it was in my Julia editor.
- hprotagonist 7y agoPersonally, matlab drives me absolutely up the wall when it comes to ANYTHING other that flipping big matricies around. As a domain-specific tool for linear algebra, I certainly prefer it over R, but as a general purpose tool it makes me want to pull my own teeth out. It's just not designed to make good pipeline tools that are maintainable, easily tested, and easily refactored, and never was. Its ability to handle things like "easy and sensible string and path manipulations" are ... rudimentary, at best, and a weird pastiche of C, fortran, java, and whatever else language was faddish when that feature was added. I have more or less one real annoyance with the technical content of matlab. (One-indexing i can live with): size([1]) ans = [1 1] which is flatly wrong, and numpy gets it right: In[0] np.array([1]).shape Out[0] (1,) Python is actually a general purpose language which has a mature scientific stack, and i feel more secure in my numerical computations there because i can have a robust test suite and command line entry points into my code that increase my confidence that my code's doing what i think it should be, and makes it easy to use. Packaging is more or less a coin-flip. Python packaging is a giant faff; matlab packaging is nonexistent (you have to vendor every dependency yourself) and expensive (your users have to shell out for the toolboxes you use, and/or have the MCR installed and can't edit your code). I'll maintain matlab when i have to, but i don't enjoy it very much.
- commandlinefan 7y agoYeah, I was more than a little surprised to see his perspective - I thought for sure he was going to rave about Julia, pick on Python a little, and skewer Matlab. My graduate thesis advisor forced me to use Matlab to do all of my master’s thesis work, and I found it to be about the most frustrating environment possible, at least for any actual programming. I’m a little shocked to read that anybody uses Matlab outside of a pure academic environment… I guess I just don’t work on sophisticated enough projects?
- scott_s 7y agoThe author of this post is in academia, so Matlab outside of academia may be as rare as you think.
- Paul-ish 7y agoI suspect doing all this in the context of a numerical analysis textbook has contributed to the authors prespective. One nice thing about Python is that you can build and prototype applications and services around it. This is important as many applications need numerical analysis. Could you imagine writing your entire application in matlab?
- jacobolus 7y agoToby Driscoll is the author of a great Matlab library for computing conformal maps, the Schwarz-Christoffel Toolbox http://www.math.udel.edu/~driscoll/SC/ http://www.math.udel.edu/~driscoll/SC/ or on github https://github.com/tobydriscoll/sc-toolbox https://github.com/tobydriscoll/sc-toolbox But I can’t say I agree with much of this. > One function per disk file in a flat namespace was refreshingly simple for a small project, but a headache for a large one. This is an absolutely horrible bonkers limitation for a “small project”. It’s “refreshing” like someone constantly dumping buckets of ice water over your head. Being able to define functions in the repl, export multiple functions from a single file, etc. are things I pretty much can’t live without in an interactive programming language. Needing to make every tiny utility function into its own file adds SO MUCH FRICTION to basic prototyping workflows. The result is that when working with Matlab I try to make as many functions as possible into lambdas, e.g. square = @(x) x∗x. But these are very limited in practice, and the workarounds to make a function work as a lambda often compromise readability, performance, correctness, and functionality. + + + Is an occasional V.conj().T @ D∗∗3 @ V really that much worse than V' ∗ D^3 ∗ V? I find that in even small programs, syntax complexity and clarity is dominated by logic flow rather than matrix multiplication. My Python programs end up dramatically easier to read than my Matlab programs, including the almost-pure-numerics parts of them. If concise built-in syntax for numerical operations were our highest ideal, we’d all be using APL. > exists a matrix class, and yet its use is discouraged and will be deprecated I think Driscoll doesn’t understand what’s going on here. There is plenty of discussion for someone who searches about the problems with the matrix class. The matrix class dated from a time when there was no @ operator, so ∗ was used for matrix multiplication instead of elementwise multiplication. This made it inconsistent with everything else and artificially limiting in obnoxious ways. Now that Python has an @ operator it is no longer useful or necessary. This has nothing to do with matrices being important or not. > Matplotlib package is an amazing piece of work, and for a while it looked better than MATLAB, but I find it quite lacking in 3D still YMMV, and maybe I’m spoiled by D3, Vega, Altair, ggplot2, etc., but I really don’t like Matlab’s plotting tools or Matplotlib. They are inflexible and full of arcane details, and produce mediocre output. We should aspire to better plotting than those in all of our environments. + + + > The big feature of multiple dispatch makes some things a lot easier and clearer than object orientation does. This is partly because Matlab’s version of “object orientation” is a horrendously broken pile of trash. > Partly that’s my relative inexperience and the kinds of tasks I do, but it’s also partly because MathWorks has done an incredible job automatically optimizing code. I’ve poked around in several large Matlab projects, and there are huge performance problems everywhere. In particular any project using Matlab’s version of object orientation ends up incurring huge amounts of overhead. + + + Overall my impression is that Julia (and Matlab’s) language choices are driven by people who want to directly type their math paper into a program with as little thought and as few changes as possible. For folks with decades of experience reading and writing math papers, this is fair enough I guess. For many people from a software background it seems like a poor choice of priorities. Programs written by researchers are often unintelligible without the accompanying paper (and sometimes with, depending on the paper). Full of 1-letter variable names defined off-screen somewhere with no comment explaining what it stands for, weird API inconsistencies, lack of structure, hacks that worked on one set of inputs for a demo but don’t handle edge cases, ....
- ggcdn 7y agoMatlab has its quirks, but I've never come across a better IDE for debugging 'scientific' code/scripts. Seeing current values by hovering over variables, the ability to pause and execute some 'testing' code, or overwrite things and carry on, being able to easily edit arrays/matrices in an excel-like table, having matrix arithmetic that doesn't look like shit when written as code... these are things that I find very useful. I use it in my field (structural engineering) for those reason alone, even if it might be slower, or more difficult to accomplish certain tasks.
- viraj_shah 7y agoI definitely understand this point. Another alternative is Python (with numpy, scipy and matplotlib) using the Pycharm IDE. It has many of the features you're talking about.
- eigenvalue 7y agoYou should check out Spyder, included with the Anaconda Python distribution. It includes most of what makes MATLAB a productive IDE. In particular, you can inspect various types of variables (including Pandas tables in a nice grid view) and watch how the contents changes as the code executes.
- stinos 7y agoSpyder is good for inspecting, coming close to Matlab (for the rather simple stuff I use it for) but it's a lacking on the code editing/browsing/plugin front. VSCode on the other hand is pretty good for the latter, is still lacking what I look for in Spyder and Matlab (i.e. if I'm debugging something, I just want a REPL in which I can type with full syntax completion, enter multiline text etc). As a result I mostly use both at the same time.. Though I wouldn't be surprised if VSCode is going to get better at one point, on github there are already multiple issues dedicated to this with at least some activity of the team.
- 0xd171 7y agoI've used quite a bit of R and Python and I've never touched Matlab. Similarly to your comment - Python has nothing that comes even close to RStudio for working with data. Jupyter, Spyder, PyCharm, VSCode/Atom with data science extensions - none of them are as good.
- diminoten 7y agoI just don't think this guy tried at all to account for his biases, and that sort of makes the entire article hard to believe beyond his MATLAB experiences.
- geoalchimista 7y agoI would dismiss a lot of his comments on Python because they were so biased by his preference of a MATLAB-like syntax.
- skybrian 7y agoI think he tried, but didn't succeed. Still, it's interesting to see how things look to a very experienced Matlab user.
- dcolkitt 7y agoMatlab sells its onerously expensive licenses by marketing itself as having unbeatable numerics performance. This is mostly a farce. The vast majority of Matlab's vaunted numerics performance comes from using MKL instead of OpenBLAS. However Intel has made MKL free software. Meaning that you can easily build NumPY on top of it. Numpy+MKL will compile down to virtually identical assembly as Matlab. There's very little reason in this day and age to pay Mathworks such an insane licensing fee.
- kevin_thibedeau 7y agoMatlab's hook is the domain specific toolkits which don't have polished open source equivalents.
- 6thaccount2 7y agoWhich ones? They seem pretty overpriced for what you get. IMO Mathematica is a better bet in most cases if you don't want Python or Julia.
- ska 7y agoSimulink is probably the biggest.
- 6thaccount2 7y agoAh. That I would agree with. The rest of the packages don't impress me as much.
- tnecniv 7y agoA lot of them are very domain specific, like controls engineering and stuff like that. If I recall, a big chunk of the code that controls Toyota engines is generated from a massive Simulink model.
- zild3d 7y ago> Matlab sells its onerously expensive licenses by marketing itself as having unbeatable numerics performance. Not at all. At Lockheed (probably one of Mathwork's biggest customers) the big use case is the toolboxes. Scientific/engineering packages like signal processing, radar, phased array, embedded/VHDL are 2nd to none and are used daily. Some sites also used a lot more of the Simulink side for modeling & simulation. [0] https://www.mathworks.com/help/signal/ref/signalanalyzer-app.html https://www.mathworks.com/help/signal/ref/signalanalyzer-app... [1] https://www.mathworks.com/help/comm/examples/rf-satellite-link.html https://www.mathworks.com/help/comm/examples/rf-satellite-li... [2] https://www.mathworks.com/help/fusion/examples/multi-patform-radar-detection-generation.html https://www.mathworks.com/help/fusion/examples/multi-patform... [3] https://www.mathworks.com/products/hdl-coder.html https://www.mathworks.com/products/hdl-coder.html
- ohsonice 7y agoMy (math graduate school) perspective: MATLAB is adored in academia for a number of reasons. It is easy to make readable small scripts for in-class examples. The debugging feature/IDE is easy to navigate. The school pays for the licenses; there is no overhead work to compile or download packages (unless you want to do something 'fancy'). I took a ML course that was taught in Python. All my Numerical Analysis and Modeling courses relied on MATLAB for examples and homework. I (as a programmer outside of just the math world) picked Julia for research. Now I do much more theoretical research, as I did not enjoy mixing coding and mathematics. A fellow student, developing PDE solvers in FORTRAN was told by a mentor to get it to work in MATLAB first and then move on to faster languages. Happy to answer any questions :)
- WhompingWindows 7y agoWhere is the discussion of R? You talk of scientific computation and don't speak of R? That's an oversight, given the majority of the scientists I know have used R. There's also STATA, which economists love, which can do somethings in my workflow much quicker than R. There is also a huge contingent of analysts that uses SAS, especially in healthcare and finance. The car analogies in the blogpost are not particularly useful... Why do people feel the need to dumb down a topic with off-the-wall analogies? Talking about Julia like it's Tesla is laughable. Tesla is a huge innovator, Julia is another tool that does similar things to the other tools. The apt analogy for Julia would be a new ICE company, not a new EV company.
- BeetleB 7y agoYes, but the majority of computational scientists do not use statistics - something that may be hard to believe. As an example, most physics programs don't even have an introductory statistics class in their curriculum. Some engineering disciplines use it more, and it is often relied a lot in industry. But most engineering research makes little to no use of it.
- kgwgk 7y ago"If your experiment needs statistics, you ought to have done a better experiment." Lord Rutherford (maybe)
- deleted 7y ago[deleted]
- hnjst 7y agoThere is also a completely different but complementary set of tools that handle formal calculous such as Maple and its libre alternative Maxima that are worth consideration.
- Lowkeyloki 7y agoSpecifically the author's mention of extended character support in Julia for math symbols, as well as the emphasis on matrix support, makes me wonder why APL didn't maintain popularity among the academic crowd.
- 6thaccount2 7y agoWell...the reason is APL can't do scientific computing well. It doesn't by default have scientific libraries and builtins for solving equations. It has a fast interpreter, but scientific computing often needs much faster. It was also late getting off the mainframe. I really like APL, but it doesn't have the horsepower for my needs.
- Aardwolf 7y ago> And there’s zero-indexing (as opposed to indexes that start at 1) What, and that's exactly the part I dislike about both Matlab and Julia! The amount of "+ 1" and "- 1"s in matlab indices you need when subdividing matrices into multiple equal sized parts is horrible. Weird, I thought mathematicians would know better what makes sense and what not. Starting with an offset of 1 is clearly what does not make sense, you start at distance 0 from your starting point.
- 0-_-0 7y agoBasically if you do any kind of modulo arithmetic on an index you need to shift by 1 in a 1-based indexing system, while 0-based just works.
- Oreb 7y agoWhich is why Julia offers the `fld1`, `mod1` and `fldmod1` functions: https://docs.julialang.org/en/v1/base/math/#Base.fld1 https://docs.julialang.org/en/v1/base/math/#Base.fld1
- lmkg 7y agoIn mathematics, a matrix doesn't have an 'offset' or a 'starting point.' I think that perceiving matrices in those terms is an artifact of thinking of matrices as sitting in an address space, where the elements of your matrix are part of a larger span that can contain other data. A matrix is a collection of elements and nothing more. Indexing starts at 1 because that's the first element in your matrix, and numbering the first element 1 makes sense. Numbering from 0 makes sense when it represents an offset into something, but a matrix isn't that. 0-based indexing just always feels to me like letting the implementation details leak out. (I don't feel this way when an array actually represents a chunk of memory, rather than a math object.) The proliferation of +1 and -1 depends on the application. Some work better with 1-indexed, some work better with 0-indexed. Personally I get annoyed at having to use `len-1` too often when working with 0-indexed arrays. This is why some languages like Julia (and FORTRAN apparently?) let you choose your index-base, which... has trade-offs.
- 7y ago
- Bostonian 7y agoThe author does not mention modern Fortran, which does have array operations, like Matlab, Python/Numpy, and Julia. I wonder if its lacking a REPL is the main reason why.
- rrss 7y agoMatlab is a calculator. It is a really nice calculator for some things, but its definitely a calculator with programming language features bolted on. I strongly believe that Matlab is unsuitable for writing most software. It is nonetheless extremely popular in some engineering fields for write-only scripts. I'll never forget when I took a controls class and we were given an option to use Python on our own or matlab with guidance and support from the professor and TAs. I chose Python since my background was slightly different that most of the students, but most everyone chose matlab. It was highly amusing to watch the whole lab suffer for days because no one understood matlab's semantics. (The base framework had been written by some expert who retired and made extensive use of both handle and value classes. Problem was, no one still involved with the clas knew what the difference was. Meanwhile, I spent about 6 seconds longer writing out np.dot a few times. Matlab is good for math. Most software (even math heavy stuff, EM simulations, etc) has little math (in terms of source, no execution time).
- enriquto 7y agoI find it quite ridiculous that a discussion about the matlab language in the context of free software projects does not even mention the excellent interpreter Octave. I say "ridiculous" to be generous; in reality it seems mostly bad faith.
- cr0sh 7y agoI noticed that, too. I don't understand why Octave is this "dark horse" when it comes to these kinds of things...
- tcpekin 7y agoI do scientific programming in both Python and Matlab. The two things that to me are major benefits of Matlab are the ease of setting up your installation, and the documentation. The Matlab documentation is amazing when compared to the numpy/scipy documentation, and is almost reason alone for a beginner to use Matlab. FWIW, the Mathematica documentation is also fantastic.
- cycomanic 7y agoThe biggest gripe I have with matlab is that it teaches absolutely horrendous programming habits. Most of the graduate students that only used/learned matlab in their studies (I'm in an engineering field) program everything into one big script which they copy around and change a couple of parameters. Now obviously you can do things properly in matlab, it's just matlabs structure encourages you not to (who thought that one function per file and no namespaces are a good idea?!) Students who used Python on the other hand typically have much better programming habits (not necessarily good), I think because of it's roots as a programming language first, you get much more exposed to programming paradigms when you learn it. The other thing I found weird was the complaint about matrixes objects being deprecated. After the addition of the '@' operator it is really the same as matlab, except their default is a matrix, while for numpy it's an array. As a side note the author complains about the '@', what about matlabs stupid decision to use the most easily overlooked ascii character for distinguishing between matrix and element wise operations. In my experience, almost all the time a matlab calculation returns weird or garbage results, the bug search is a "find the missing '.'
- inamberclad 7y agoWhat kills me about MATLAB is that it's CLI still doesn't have any terminal shortcuts beyond Ctrl+C. No Ctrl+D, no Ctrl+W, no Ctrl+left arrow or Ctrl+right arrow. It's also a gigantic memory hog and all the plots are copy-on-write, and the memory usually isn't deallocated afterwards.
- musicale 7y agoMandatory matlab in coursework is usually harmful and should be avoided if possible. Julia and python are full-featured languages that aren't marketing for mathworks.
- cfusting 7y agoThe choice of language usually comes down to the packages. In any of the three aforementioned languages one can easily and quickly manipulate matrices short of an unwillingness to learn. Julia is nice because it's fast with native code. Python is nice because of Scipy. Matlab is nice because it decides how to spend your money without cause. I'm an AI researcher / practitioner. For me code accompanying papers is very useful and usually this code is in Python. Occasionally it's Matlab but let's be honest, who cares about those papers :). I'd love to use Julia but the package support just isn't there. Ironically people like me are supposed to be writing this code but with a demanding job and a family it's not likely I will be improving their DataFrame effort anytime soon. Anyway the MAIN reason I use open source software is because if it isn't working correctly I simply fix the code myself. This isn't possible in the proprietary world. Why would you trust your research or production work with code you can't see and edit? There's been a lot of talk about documentation. Docs are secondary sources, like WIRED, read the code if you're serious about being correct. Even (especially) hired hands make mistakes and fail to write good tests. This article reminded me of the fictional Simpson's news article "Old Man Yells at Cloud". It's funny, and he may have a point, but it has no relevance.