Live data from Hacker News

Python+Scipy+Matplotlib vs Matlab?

news.ycombinator.com

21–30 of 45 posts

Re: Python+Scipy+Matplotlib vs Matlab?

#21
post #9

Matlab is, to the programmer with experience in almost any other language, a tremendous horror. The language is almost as cobbled together and inconsistent as PHP with the added bonus of being worked on almost exclusively by engineers instead of people who actually want to write programs (this coming from an engineering student here). That being said, if you have the mathematical chops to rearrange your problem into…

I don't agree Matlab is a horror - and I am a CS person, not an "engineer" as you say. It is an excellent domain-specific language. It might not be a good general-purpose language, but it was never intended to be that. True, some of the "bolt-on" parts of Matlab feel inconsistent, but the matrix/vector/tensor core is very elegant and powerful.

Re: Python+Scipy+Matplotlib vs Matlab?

#22
post #21
post #9

Matlab is, to the programmer with experience in almost any other language, a tremendous horror. The language is almost as cobbled together and inconsistent as PHP with the added bonus of being worked on almost exclusively by engineers instead of people who actually want to write programs (this coming from an engineering student here). That being said, if you have the mathematical chops to rearrange your problem into…

I don't agree Matlab is a horror - and I am a CS person, not an "engineer" as you say. It is an excellent domain-specific language. It might not be a good general-purpose language, but it was never intended to be that. True, some of the "bolt-on" parts of Matlab feel inconsistent, but the matrix/vector/tensor core is very elegant and powerful.

I would consider Matlab to be a DSL grown out of control. If you are working purely with matrix/vector/tensor math, as you say, you can be reasonably comfortable with the language as long as you remember to double-check the docs on nearly every function before you use it just in case there is some strange edge-case it handles awkwardly.

Unfortunately, in any real project I've ever done with Matlab you cannot survive just inside the matrix DSL and once you start touching the bolted-on bits you lose patience very quickly.

So, I suppose I agree, it's a nice DSL, but I'd also wager that the majority of people using it don't realize the limitations implicit there.

Re: Python+Scipy+Matplotlib vs Matlab?

#23
post #22
post #21

Earlier quoted context omitted.

I don't agree Matlab is a horror - and I am a CS person, not an "engineer" as you say. It is an excellent domain-specific language. It might not be a good general-purpose language, but it was never intended to be that. True, some of the "bolt-on" parts of Matlab feel inconsistent, but the matrix/vector/tensor core is very elegant and powerful.

I would consider Matlab to be a DSL grown out of control. If you are working purely with matrix/vector/tensor math, as you say, you can be reasonably comfortable with the language as long as you remember to double-check the docs on nearly every function before you use it just in case there is some strange edge-case it handles awkwardly. Unfortunately, in any real project I've ever done with Matlab you cannot survive…

...some strange edge-case it handles awkwardly.

Or stupidly. I don't know if the following should qualify as an edge case generally, but it does in Matlab.

The controls lab in the aerospace department at the U of W had a wonderful inverted cart-pendulum device that a grad student was doing some seriously freaky non-linear control research on. We were tasked, as part of a lab, to write a controller in Matlab that would balance the pendulum and move the cart to a designated position. After trying for days to come up with a combination of gains to result in stable control, I decided to write an evolutionary algorithm to choose a controller.

It was dead simple. The genome was a list of gains. The code created generations of genomes and then ran them through the simulation. The tricky part (for me at that time) was finding the settling time (walk backwards from the end of the data, checking for values outside of the tolerance). Choose the winners, perturb, preserve best performers, and go around again. Doing all the steps by hand worked wonderfully.

When I ran the code, I got combinations of gains that resulted in massively unstable systems; systems that overshot off the chart as soon as physically possible given the hardware. What was going on?

It turns out, when I ran the simulation from the command line, Matlab graciously accepted my 5-second simulation time. However, when run from a script, Matlab ignores that parameter and runs the simulation until the output careers off the chart. Because I was looking for a minimum time with no overshoot, my algorithm was finding combinations of gains that overshot steeply enough to convince Matlab to stop simulating ASAP! It was bizarre. My secondary condition was minimum overshoot, so I got solutions that were exactly steep enough to cause the simulation to stop when the output hit the desired value!

A friend of mine stumbled on to a workable combination of gains. I used those.

Re: Python+Scipy+Matplotlib vs Matlab?

#24
I worked for Enthought (the people behind SciPy, and now NumPy, as Oliphant works for Enthought, as well) for several years when I lived in Austin. Nearly all of the guys that work on SciPy and Matplotlib came from using Matlab in some capacity or another. I've never worked with Matlab, but from the examples I've seen, I much prefer the Python version of things to the Matlab version.

I'll also mention that SciPy is in use at some of the biggest companies in the world, and because of its stronger programming language base, it can be used for much larger problem sets than Matlab. Massive fluid dynamics computing projects, requiring clusters of machines, for example, is feasible (and being done) with SciPy. Likewise for geological data analysis. I don't know anything about parallelizing Matlab, but I'm guessing the possibilities are much greater with Python.

And, of course, Python skills are probably more transferable to other work.

I don't see how you could lose by trying SciPy. It's free, has a great community of incredibly smart people (it's the community with the highest ratio of PhDs to others that I've ever been a part of), and is fun to play with.

Re: Python+Scipy+Matplotlib vs Matlab?

#25
post #7

If you're working for personal gain, you're probably better off with the Python+ solution because it's a) cheaper, and b) translates into knowledge that can be harnessed in other applications you write in Python. You're probably unlikely to write a real application in Matlab. If you're going to be doing work at a university, you may find reluctance from the persons you are working with as I did a few years back. The…

Space Telescope Science Institute (they run Hubble under a NASA contract) has contributed to development of numarray and numpy.

Re: Python+Scipy+Matplotlib vs Matlab?

#26
I don't like the looks of the pylab graphs, I wouldn't put them in a paper. However, there's also PyX (http://pyx.sourceforge.net/index.html) which is a little more verbose in usage but makes very nice "latexy" plots that go well along with a latexed paper. And it can do some really advanced stuff, too, that I wouldn't even know how to begin thinking about doing in pylab.

Re: Python+Scipy+Matplotlib vs Matlab?

#27
I find that matlab is a great program to try out new ideas and algorithms when you are just starting out. The plotting library is also very easy to use and there are many helpful built in functions for matrix, linear algebra manipulations. However the language itself is a horror to code in, its based on fortran. I still really hate the 1 based array indexing after using it for years.

Re: Python+Scipy+Matplotlib vs Matlab?

#28

Most universities have studen license servers for Matlab afaik. And, Matlab is really really, annoyingly powerful. You've got almost anything to try your ideas, implement an academic paper. But, it is slow (execution time). Prototype with Matlab, implement with C++. That's what I usually prefer. I am not a Python expert, just learning it. but I think it will be slower than C, and less powerful than Matlab, from my pe…

We use python for pretty much everything in my research group -- high-level scripting of simulations written in C; controlling experiments over serial, GPIB, usb; and data analysis and plotting for publications. I used Matlab for several years prior, but got really annoyed by the limits of the language when you try to do anything beyond matrix manipulation. Python + scipy + pylab is a pretty effective replacement for matlab prototyping and data analysis, with a much better general purpose language and FFI. Anything that needs to be fast you can write in C/C++ and wrap with swig or ctypes so that you can still use a high-level language to run all your simulations, and do the data analysis as well.

Re: Python+Scipy+Matplotlib vs Matlab?

#29

I find that matlab is a great program to try out new ideas and algorithms when you are just starting out. The plotting library is also very easy to use and there are many helpful built in functions for matrix, linear algebra manipulations. However the language itself is a horror to code in, its based on fortran. I still really hate the 1 based array indexing after using it for years.

That sounds like me about IDL... ;-)

Re: Python+Scipy+Matplotlib vs Matlab?

#30
I've used both and I greatly prefer python+scipy+matplotlib. Because it's a real programming language, unlike Matlab's clunky Basic-like thing. So if matplotlib doesn't do what you need, you can extend it or just write something custom in GTK+Cairo. The depth and stability of scipy & matplotlib is very impressive.
Post reply on HN