The Power of Matlab

Now here is a language that I have a love-hate relationship with. I hate it so much because every single thing you do uses a different function, or the same function, which does something totally different.
Example: You use one function to find the derivative of two polynomials multiplied together. Now call the function again, with the same two polynomials (which are exactly the same as normal numbers) but ask for two answers instead of one, and it's d/dx (a/b) instead of d/dx (a*b) .

Simple simple simple problems require me to hang off the pages of the Matlab textbook like I'm religious, just because there are so many functions and different uses for the same functions and subfunctions that don't do anything different.

So now for the painful admission of how Matlab is a superior language. It handles numbers really well! (Not surprising, since that's what it's designed for...)

Case in point: The prime sieve
This is a good exercise to keep around for when you're teething on a new language to get a feel for the ropes. How to check for remainders, how to iterate along a list, how to grow a list, etc. My version in C comes up to a total of 69 lines of code, comment free. Matlab? Seven. Seven freakin lines for something that takes more sentences than that to describe.

% Seed the list of primes with 2
primes = 2;

for currnum = 3:100000 % currnum is 3 to BIG NUMBER
% If the number is divisible by any number in the list of primes
% skip on to the next number in the for loop
if (find(mod(currnum, primes)==0))

% Since no multiples were found, add this number to the end of the
% list of primes
primes = [primes currnum]; % Notice how the list just grows as you
% define it as itself and one more

So I really hate this language, and really hate the class teaching this language, but I have no choice but to admit that as far as scientists are concerned, this is a great language. I want to know exactly what the computer does when (does the if statement continue to evaluate after finding a multiple?), where when someone is solving a problem, they just want the freakin answer.

Popular Posts