Over the past year and a half I've incorporated Matlab into my daily work. It's a tremendously useful tool for experimenting with image processing and linear algebra. It's got a nice array-slicing syntax, so the second column of a matrix, M is M(:,2), and every other row in reverse order is M(end:-2:1,:). It also has some very useful easy graphing commands, so if you have an array of values sampled at a corresponding array of x and y positions, you can say surf(x,y,A) and get a nice 3D surface plot. It also has other nice language features like the ability to return a list of results from a function and assign those results separately as in [V,D]=eig(A).
However, it's got some serious serious shortcomings. First, it's closed source and expensive, so if you prototype with it, you have to then either port it to another language or kludge together scripts to call Matlab—not cool. Second, unlike any language other than assembly, values returned from functions are magic in that you can't index into them. So while the function eig(A) returns a vector of eigenvalues of A, if you want just the first one, you can do v = eig(A); v = v(1) but you can't do v=eig(A)(1). This is particularly tiresome with a language geared for matrices in which you might want to nest a series of functions indexing each as you go. That is, you couldn't do foo(bar(baz(A)(1:2:end))(:,:,0)), you'd have to assign each result to a temporary. Third, Matlab indexes from 1. Yes that's what everyone expects when they start programming, yes mathematicians index from one, but for twiddling with arrays, zero is just easier.
Finally, Matlab doesn't lend itself to creating functions or data structures. In general each function is in exactly one file, leading to terrible code reuse. You can add more functions to the end of a file but those can only (?) be used as subroutines within that file, leading to a terrible lack of code reuse. Worse, what little support Matlab has for classes is done through a special directory for the class and a separate file for each method(!)
Fundamentally, there is a need for an interpreted language capable of being run interactively but that is also a real standard programming language, not some kludgy interpreted dialect of Fortran. That something needs to have mathematical and graphing batteries included .
Fortunately, there is a collection of Python packages that have a very solid chunk of this covered: matplotlib, scipy, and ipython. Not only do they have all of the 2D graphing that Matlab has with a similar syntax, but they use the (awesome) Anti-Grain Geometry library for graphing, so you get plots way better than the aliased 1990s-style plots that Matlab dumps out.
Python has language support for array slicing and for returning tuples, but it is also a Real Programming Language in that you can write a linked list or a graph without having to hack it on top of arrays. It isn't designed with array programming in mind the way Matlab was, so the syntax for arrays is slightly more cluttered, but not by much. The big differences being that Matlab has special element-wise operators and has concise array construction notation, so a.*b in Matlab returns the array formed by multiplying a(i) by b(i).
So give it a try. Install the appropriate packages and start doing your scientific computing in an actual programming language.
ben@endash:~$ ipython -pylab ... In [1]: x=r_[0:100:0.1] # Generate [0, 0.1, 0.2, ..., 99.9] In [2]: plot(x, sin(x)/x) # Nice pretty plot. Out[2]: [<matplotlib.lines.line2d object="object" at="at" 0xa0ee8cc="0xa0ee8cc">] In [3]:
Can Matlab rasterize images to look this nice?:

PS If you want a blast from the past, Python even has a turtle library, giving it the same drawing sematics as Logo.
from turtle import Turtle
t = Turtle()
for in in (0,1,2,3):
t.forward(100)
t.right(90)
Not only is Python making programming as fun as it was in my hard-core Logo days, it's doing it in a language that can simultaneously be used for Logo-like simplicity and Matlab and driving high-performance computing. Go Python! |