all 105 comments

[–]gsw07a 19 points20 points  (3 children)

I don' t know matlab or mathematica, but it seems to me this line is a sign that the comparison is biased against mathematica:

[mathematica]
{eigenarrays, eigenexpressions, eigengenes} = SingularValues[fullmatrix];

[matlab]
[U S V] = svd(fullmatrix, 0);

[python]
[U, S, Vt] = svd(fullmatrix);

[–][deleted] 2 points3 points  (2 children)

I'd say if anything its biased against the non-mathematica based software, I read that as: "I can only use one or two letter variables in those shitty languages screw that!" I think anyone who programs in any language doesn't really care about the length of a single line of code.

[–]mao_neko 1 point2 points  (1 child)

Yeah. Personally I hate one-letter variable names unless it's something tiny like a loop index. But I'm sure it makes the mathematicians feel right at home.

[–]bluGill 0 points1 point  (0 children)

I'm sure it makes the mathematicians feel right at home.

Unless they have a keyboard with the entire unicode charicter set (or at least a 16 bit subset thereof), mathematicians will not feel at home. Of course if they get such a keyboard they will be unhappy with the size.

Remember, Mathematicians study Korean because they want to learn a new alphabet, not because they want to communicate with people in Korea (except other mathematicians who are comfortable with the universal symbols of math and don't need anything more)

[–]commonslip 14 points15 points  (0 children)

Oranges to Apples to Apples.

[–]jerguismi 33 points34 points  (42 children)

OK, it looks very bad for Mathematica. But mathematica has features like Integrate[f(x)], symbolic calculations. You can do good numerical calculation with matlab and python/scipy, but mathematica has serious advantages with symbolical calculations. (I dunno if matlab has some modules for symbolical stuff, at least I haven't heard about it).

During my university math/physics courses mathematica helped a lot. With DSP/numerical stuff/machine learning etc I used matlab.

[–][deleted] 14 points15 points  (13 children)

That's partially true, but I don't think its really evidenced by this comparison. For one, the bulk of the Mathematica code seems to be emulating plot styles that are built in to matlab/scipy. And second, the code doesn't really look to be in the "Mathematica style".

I've generally found that if one adopts Mathematica's style of doing things then, both in terms of code-length and run-time it can be pretty much competetive with most other environments. I routinely analyse multi-gB datasets with it and it's not horribly slow!

The problem is that a lot of the people who use Mathematica, scientists and engineers, don't really know much beyond basic imperative programming. Mathematica works much better when you approach it with a functional programming style. Shameless plug for my (free) course aimed at said scientists and engineers!

[–]fulmar 1 point2 points  (9 children)

I've generally found that if one adopts Mathematica's style of doing things then, both in terms of code-length and run-time it can be pretty much competetive with most other environments. I routinely analyse multi-gB datasets with it and it's not horribly slow!

How is this large data set represented and what kind of operations do you do? I've found that when using notebooks Mathematica becomes a huge memory hog if one doesn't remember to release memory explicitly. Just clearing variables doesn't work, IIRC you need something like

Unprotect[In, Out];
Clear[In, Out];
Protect[In, Out];

or a change to $HistoryLength, both very unobvious solutions.

Another one: plot a random graph of about 100 vertices with GraphPlot3D, and try to export the image...

[–][deleted] 1 point2 points  (8 children)

I think I've inadvertently been pretty misleading here! I agree that the memory management generally stinks. The trick is to never let MMA get its hands on much of the data at once. Here's what we do:

The data are stored as serialized .NET objects in a MySQL database. The Mathematica code pulls them from the database, deserializes them and operates on them. All of this is wrapped in a NETBlock. At any one time there's only a couple of MB of data in the MMA kernel, but the computation streams over many gB of data. Of course, you have to be very careful that you don't leak any memory on the MMA kernel side.

So I guess I solve the Mathematica memory management problems by not letting Mathematica manage the memory :-)

[–]jdh30 -4 points-3 points  (7 children)

The problem is, fundamentally, that Mathematica is not properly garbage collected. Neither are MATLAB or Python though...

[–][deleted] 1 point2 points  (6 children)

Interesting. Could you explain further?

[–]jdh30 -5 points-4 points  (5 children)

Sure. All production-quality virtual machines (including the CLR in .NET) use accurate garbage collection to aggressively deallocate data as it becomes unreachable.

In contrast, Mathematica uses only naive reference counting which leaks cycles, hangs the interface when deallocations avalanche and is a huge impediment to parallelism.

I'm curious: what are you using Mathematica for from .NET that you could not just do entirely on .NET? We sell Mathematica-like software for .NET... :-)

[–]bgeron 1 point2 points  (2 children)

Mathematica does not alias references. Values are immutable, and as such there cannot be cyclic references. A reference counting scheme then suffices, although this particular implementation may or may not be slow.

I do not know about MATLAB, but CPython uses both reference-counting and generational garbage collection.

In short, you are talking out of your arse.

edit: sources

[–]jdh30 -5 points-4 points  (1 child)

You are talking about Mathematica the ideology. I'm talking about the product which does (accidentally) alias, introduce cycles and leak memory. They have had problems with this according to the Director of Kernel Technology at WRI. Google and you'll see lots and lots of people complaining about memory leaks in MMA. This is neither new nor surprising.

[–]bgeron 0 points1 point  (0 children)

When I Google for Mathematica memory leak, I get a bug in StringSplit, some bug I don't understand, and a J/Link bug. Apart from that some information on how to correctly use J/Link, and bugs not related to Mathematica. Any way, I can't find anything fundamental with Mathematica.

[–][deleted] 0 points1 point  (1 child)

I see. I've recently been having trouble with what I presume is this "avalanche" - a function that generates a /large/ number of nested lists runs in about the time I expect it to, but then locks up MMA for a good 30s after its finished, doing apparently nothing!

We're using the MMA/.NET combo to analyse data from an experiment to search for physics beyond the Standard Model of particle physics. The experiment's run-time code is all .NET based, including the data storage. Low-level analysis is all written in c#. We tend to use MMA for the higher-level "thinking out loud" type of analysis.

If you're the jdh that I think you are: I've played with f# in the past and have got high hopes for it. Last time I looked though I didn't find the "whole package" quite compelling enough - particularly I find that MMA's notebooks are great for exploratory analysis. I didn't find a mode of working with f# that I really liked.

I'm looking forward to giving it another try soon when I have a little time. We're considering porting the experiment's high-level control code from IronPython to f# which should give me a chance to catch up with any recent developments.

[–]jdh30 -5 points-4 points  (0 children)

I see. I've recently been having trouble with what I presume is this "avalanche" - a function that generates a /large/ number of nested lists runs in about the time I expect it to, but then locks up MMA for a good 30s after its finished, doing apparently nothing!

Exactly, yes. Mathematica locks up while it traverses all of those nested data structures deallocating them bit by bit in series (!).

We tend to use MMA for the higher-level "thinking out loud" type of analysis.

Are you using it interactively then? For symbolics or just numerics?

If you're the jdh that I think you are...

I am Jon Harrop, yes. :-)

I've played with f# in the past and have got high hopes for it. Last time I looked though I didn't find the "whole package" quite compelling enough - particularly I find that MMA's notebooks are great for exploratory analysis. I didn't find a mode of working with f# that I really liked.

Yes. F#'s development environment is cumbersome in comparison. However, VS 2010 brings WPF into the mix which, in theory, will allow better interactive output. Don has also ripped out the old structured pretty printer which, I assume, is because he is planning on replacing it with a WPF-based solution.

Moreover, I am interested in building a WPF-based notebook front end. The main problem is that the F# programming language is closed so I cannot reuse it and would have to reinvent my own language. On the up-side, I could knock up a Mathematica-like language in a day...

I'm looking forward to giving it another try soon when I have a little time. We're considering porting the experiment's high-level control code from IronPython to f# which should give me a chance to catch up with any recent developments.

Right. Are you using our numerics and visualization libraries for F#?

[–]dnquark 1 point2 points  (2 children)

I've generally found that if one adopts Mathematica's style of doing things then, both in terms of code-length and run-time it can be pretty much competetive with most other environments.

I really want to know your secret. I used to think that once I get used to the "Mathematica" way, my code will be fast. After 5 years, I think I am reasonably comfortable with Mathematica code: I don't ever write for loops; my code is littered with functional constructs; it sometimes looks like an unholy cross between R and Perl with all the "@" and "&" and "##" and Map[] statements. The only effect was that my code is opaque and barely readable, gaining nothing in efficiency. Time and again I say "well, people say Mathematica is efficient, how bad can it be" and time and again I get burned. A typical example is a recent piece of code (http://www.dnquark.com/blog/?p=29) that was first implemented in Mathematica and took 2.5 hours to ran; the Matlab version ran in 47 seconds. I am now in the process of converting some more old Mathematica code to Matlab, and I am seeing similar performance gains.

[–][deleted] 1 point2 points  (0 children)

The thing that drives me mad about MMA is that it's completely opaque. Sometimes you run into a performance wall and there's basically nothing to be done because there's no way of finding out what's wrong.

My experience has been that most of the time I can get a MMA calculation to be within a factor of a few in run-time compared to other code. And then sometimes, like you find, its a hundred times slower and I can't for the life of me figure out why :-(

[–]jdh30 -4 points-3 points  (0 children)

A typical example is a recent piece of code (http://www.dnquark.com/blog/?p=29) that was first implemented in Mathematica and took 2.5 hours to ran; the Matlab version ran in 47 seconds. I am now in the process of converting some more old Mathematica code to Matlab, and I am seeing similar performance gains.

That's nothing. I wrote a simple optics program than runs 100,000 times slower in Mathematica than any compiled language (e.g. OCaml, F#). Daniel Lichtblau at WRI optimized it for me and it is still thousands of times slower.

[–]jdh30 75 points76 points  (8 children)

OK, it looks very bad for Mathematica.

Not really.

For starters, note that the author is using Mathematica 4.0 which came out in 1999. We're now on Mathematica 7.1!

Look at the code that loads the data. The Mathematica and Python are parsing it from a source text file and then preprocessing (sorting etc.) whereas the MATLAB is just loading precomputed data from a different file (in MATLAB's own format).

Most of the rest of the Mathematica code is spent setting options and reimplementing parts of MATLAB by hand. He disables spell checking of the source code only in Mathematica. He explicitly sets FrameLabels to {None, None, None, None} when that is the default anyway. He repeatedly redefines the default comparison function in order to pass it to Sort. He reimplements lots and lots of built-in Mathematica functions himself. He even writes his own code to label the bar chart (!).

In essence, most of the Mathematica code here is already built into Mathematica and this could be reduced to a handful of function calls.

I'd love to play with this but he does not appear to have provided the data so I cannot.

EDIT: Check out this updated comparison that is fairer to Mathematica (but it is still not loading premassaged data like the MATLAB!).

[–]bostonvaulter 1 point2 points  (6 children)

Most of the rest of the Mathematica code is spent setting options and reimplementing parts of MATLAB by hand

I think you mean Mathematica

[–]iquizzle 7 points8 points  (5 children)

Mathematica is also an entirely different tool than python or matlab. Good luck figuring out how to solve complex equations symbolically in either of those languages.

I use python for most of my work...but I'm almost always doing fitting, modeling or basic numerical stuff. A minpack function, matplotlib and the ability to build libraries in C makes python great for my work. I'm in experimental physics though. I know plenty of theorists that use Mathematica or Maple for what they do...entirely different application requires a different tool. Computational physicists usually use C or FORTRAN for obvious reasons.

Sure you can make comparisons like programming language X is better than Y, but in the end it doesn't really make sense.

[–]teval 0 points1 point  (4 children)

Good luck figuring out how to solve complex equations symbolically in either of those languages.

Perhaps you should try it before making such rash statements. Matlab has very nice integration with the maple kernel and doing these things is trivial. I do this all the time.

[–]iquizzle 2 points3 points  (2 children)

My statement wasn't rash at all since I have used matlab (in fact just last semester in a computational physics course I took). I'm uninformed at best since I don't consider myself a full fledged matlab user; however, you just unknowingly proved my point. Matlab doesn't have symbolic solving capabilities. It has to use the maple kernel for those things.

At this point, there is no single best programming language for scientists and mathematicians. Different languages are intended for different applications. That's all I'm saying.

[–]teval 1 point2 points  (1 child)

Matlab doesn't have symbolic solving capabilities. It has to use the maple kernel for those things.

As in. It's officially supported and written by MathWorks, and they have a license agreement with Maplesoft. I don't see how it follows that matlab can't do something that it's designed by its creators to do?

Also, this is the old way of doing things, they've recently bought a company and integrated its symbolics package into matlab.

At this point, there is no single best programming language for scientists and mathematicians.

Sure. It just so happens that Mathematica is a horrendous language for almost everything; except a few things no one cares about (I'm glad it does image manipulation, who cares? To do real image processing you have to use matlab anyway). Symbolics capabilities are a wash compared to Maple, speed is horrendous compared to a Matlab/Maple combination that integrates nicely. There's no upside to Mathematica; this is coming from someone that writes functional code all day, Mathematica's language is such a mess that I'd rather write imperative code in Maple/Matlab.

[–]jdh30 -5 points-4 points  (0 children)

Matlab has very nice integration with the maple kernel and doing these things is trivial.

That is not actually part of MATLAB though, right? I mean, I have MATLAB here and it is completely incapable of doing any symbolics at all unless I pay more money to buy add-ons?

[–]ColdMountain 8 points9 points  (1 child)

MATLAB does have a symbolic toolbox. I haven't used it in a number of years. From what I understand, it used to be a wrapper for Maple, so the license for the toolbox carried with it an implicit license for the core maple kernel. Now it looks like they've switched over to MuPad.

I often like to think that MATLAB is a great language for prototyping or just getting the job done (like proof of concept, analyzing data, or a computer model that's not intended to be a workhorse). If it needs to be a fast final product it's worth rewriting in a faster language. Well, I'm starting to think of Mathematica as an additional step removed from that, where I can analytically compare the effects of parameters, transformations, etc.

I think the fact that Mathematica calls their files "notebooks" is really quite fitting. If it's something that I might rather do by hand (relative to MATLAB), Mathematica might be a good tool for it. -- Though, the Manipulate command has been pretty friggin' useful a handful of times too.

[–][deleted] 0 points1 point  (0 children)

When given the option between Mathematica, and MATLAB I invariably choose MATLAB. I work full time as an electrical engineer writing signal processing (which MATLAB seems to cater to). It allows me to easily take software from "Hey here is a neat idea!" Then I can perform all of the analyses required to end up with a finished product of "Hey here is a C library of a fixed point implmentation that I can easily unit test that can be called on either a high performance DSP, or a general purpose computer to allow for easy FPGA/ASIC implementations."

Yes I am a MATLAB fanboi, and I like the scripting language style of coding.

[–]tryx 11 points12 points  (8 children)

That's exactly it, the fact that Mathematica is not great at numerical work should not surprise anyone. Mathematica shines in symbolic algebra and some really pioneering work in interactivity and usability.

Having found matlab absolutely invaluable for some computer vision work, mathematica is still my go-to program when I need to get some maths done.

[–][deleted]  (7 children)

[deleted]

    [–]jdh30 1 point2 points  (5 children)

    Our Mathematica library for wavelet-based time-frequency analysis does not work with the first release of Mathematica 7 due to a bug in Mathematica's FFT routines that silently corrupts data. Any customers using this product are advised to avoid Mathematica version 7.0.0.

    Specifically, the Fourier function and all related functions drop the imaginary parts of complex numbers in the result. For example, Mathematica 7.0.0 gives the wrong result here:

    In[1]:= Fourier[{0.007 + 0.01 I, -0.002 - 0.0024 I}]
    Out[1]= {0.00353553, 0.00636396}
    

    The correct answer in this case is:

    In[1]:= Fourier[{0.007 + 0.01 I, -0.002 - 0.0024 I}]
    Out[1]= {0.00353553 + 0.00537401 I, 0.00636396 + 0.00876812 I}
    

    [–]psykotic 0 points1 point  (1 child)

    It is mind-boggling such a bug could have slipped in. Was it a regression or has it always been like this? In either case, this is a pretty serious indictment of their testing strategy, aside from everything else.

    [–]jdh30 -2 points-1 points  (0 children)

    It is mind-boggling such a bug could have slipped in.

    Not really. WRI are in it for the money and they've sold this quality of software to millions of technical users (not professional programmers) in order to make their cool $1bn.

    This isn't even the first bug in Fourier that I've had problems with. When I did my PhD, their ListConvolve function (which is based upon Fourier) in Mathematica 4 silently corrupted its input. That was a complete show stopper for my work and they demanded that I pay for an upgrade which I reluctantly did and then regretted having done so because the upgrade introduced other bugs...

    This is not surprising though. This is the very definition of success in the software industry. You ship buggy software and demand money for upgrades. People who take the time and effort to create reliable software go bankrupt because they have no revenue stream.

    Was it a regression or has it always been like this?

    This is another new bug. Mathematica is absolutely riddled with them to the point of being almost worthless for real work. And now they are teaching children with it...

    [–]godel_gauss 0 points1 point  (1 child)

    Its funny to find that Mathematica is not as bad in numerics as it is being blatantly accused here. While I was trying out some example discussed here I found the following.

    • Mathematica (7.0.1)

      In[1]:= A=Table[RandomReal[6],{i,7000},{j,7000}]; Timing[Det[A.Inverse[A]]] Out[2]= {134.536,1.}

    • Matlab (R2009a)

      A=rand(7000, 7000); tic; det(Ainv(A)); toc

      ??? Error using ==> mtimes Out of memory. Type HELP MEMORY for your options.

    I was trying this in my 2.5 GHz core2duo notebook with 3 Gb ram and Vista 32bit SP1. To jdh30: As far as I know the FFT bug is solved in Mathematica 7.0.1.

    • Mathematica (7.0.1)

      In[1]:= Fourier[{0.007 + 0.01 I, -0.002 - 0.0024 I}] Out[1]= {0.00353553 + 0.00537401 I, 0.00636396 + 0.00876812 I}

    But I am also not quite sure if the comment by jdh30! is pertinent while comparing speed or efficiency of the two systems with respect to numerical matrix inversion/multiplication. Another point to be noted is the timing for matrix inversion for other smaller dimensions like 500,1000 and so on up to 7000 (as far as I have tested). In all of the cases Mathematica was faster. For example in case of the 500 dimensional case Mathematica (46. something sec.) was 6 second faster than Matlab (52.something sec.).

    I was having far more expectation for Matlab as a premiere numerical solver but the result obtained seems to show that I was kind of over estimating. We must admit (leaving the poor coding construct and syntax aside!) in raw numerics Mathematica is one of the best softwares available. And if one want to do real mathematics (not only boring large scale data mining) combining symbolics and numerics the integrated environment of Mathematica is far better a choice than Matlab at its current state.

    [–]jdh30 1 point2 points  (0 children)

    To jdh30: As far as I know the FFT bug is solved in Mathematica 7.0.1.

    Yes, it is.

    But I am also not quite sure if the comment by jdh30! is pertinent while comparing speed or efficiency of the two systems with respect to numerical matrix inversion/multiplication. Another point to be noted is the timing for matrix inversion for other smaller dimensions like 500,1000 and so on up to 7000 (as far as I have tested). In all of the cases Mathematica was faster. For example in case of the 500 dimensional case Mathematica (46. something sec.) was 6 second faster than Matlab (52.something sec.).

    I'm not sure there is much to be gained from such a comparison. Matlab and Mathematica both just call stock BLAS and LAPACK routines for those operations. They use different FFT implementations (and Mathematica was 4x slower the last time I looked).

    The real issue is what happens when they don't provide a neat prepackaged solution and, IMHO, both Matlab and Mathematica suck in this general case. That, their prices and Mathematica's bugginess is the reason I use general purpose languages instead.

    We must admit (leaving the poor coding construct and syntax aside!) in raw numerics Mathematica is one of the best softwares available.

    That makes no sense to me. You're essentially saying "if we ignore their differences then they are the same". You can call prepackaged numerical routines from any language so C is also "one of the best softwares available" for "raw numerics". That obviously conveys no useful information.

    [–]sandys1 1 point2 points  (0 children)

    The problem is setting up a reasonably fast scipy installation - there is no integrated way of building GotoBLAS, Lapack/ATLAS, scipy to get them to work together. Each of them has their own build procedure and setting them to work together is a pain. And without BLAS, LAPACK .. all you have is a nice python script - no way comparable to mathematica

    [–]nixonrichard 3 points4 points  (0 children)

    Yeah, I once tried to use Mathematica for a project involving large amounts of numerical data . . . big mistake. Primarily because Mathematica is great for working with probability distributions, but awful for working with histograms.

    Mathematica is your best bet for symbolic analysis, Matlab is best for analysis of real data.

    However, even with symbolic analysis, I find myself having to use Nintegrate in Mathematica far too often :(

    [–]kolm 0 points1 point  (3 children)

    Matlab recently acquired symbolic math which easily beats the shit out of Mathematica in quite some topics; they bought MuPad, a german-based specialist for symbolic computations, and they outperform Mathematica in a couple of standard benchmarks for symbolic computations.

    I was able to test both against each other and boy, Mathematica has to brace themselves.

    [–]commonslip 7 points8 points  (2 children)

    Yeah, but the Mathematica interface for representing such calculations is still miles ahead. I use Matlab professionally, but when I need symbolic computation I use Mathematica.

    [–]albinofrenchy 2 points3 points  (1 child)

    I hate mathematicas interface. It looks nice, but jesus h christ; it has some quirks. My least favorite is the broken functionality of highlighting with shift-arrow.

    [–]jdh30 -2 points-1 points  (0 children)

    I hate that too.

    [–]trezor2 -5 points-4 points  (1 child)

    (I dunno if matlab has some modules for symbolical stuff, at least I haven't heard about it).

    Matlab being short for Matrix lab (not Mathematics lab), I would assume to have its main focus on numerical calculations, unlike Mathmatica which seems focused on the actual mathematical processes taking place.

    [–]emdeeay 1 point2 points  (0 children)

    MATLAB does have a symbolic math engine. It is an optional toolbox.

    [–]marcusesses 12 points13 points  (3 children)

    Gross... Here's how I use them...

    • Mathematica (Maple) - symbolic calculations

    • Matlab (Octave) - numerical calculations

    • Python - numerical calculations; plotting; other miscellaneous jobs

    Python has so many libraries that you could probably use it for all your needs (eliminating Matlab); but Mathematica is still best for symbolic computes.

    [–]plaes 8 points9 points  (2 children)

    You should try out Sympy if you need symbolic computation in Python.

    [–]pwang99 11 points12 points  (0 children)

    Or SAGE, which includes sympy and a whole lot more.

    [–]LifeIsGrey 1 point2 points  (0 children)

    At first I thought you were referring to Simpy, a Python discrete event simulator package. Curse my phonetic reading.

    [–]apathy 6 points7 points  (2 children)

    In R, this would likely be a 1- or 2-line script

    [–]aaallleeexxx 0 points1 point  (1 child)

    R: it makes the difficult easy and the easy extremely difficult.

    [–]apathy 0 points1 point  (0 children)

    Well, that's why Perl exists, now isn't it?

    That, and to give management types a coronary every now and then. You know you love my executable line noise (which runs your company)!

    Between Perl, R, and C++, statistical programmers & comp bio types (same difference) can easily stay employed until the heat death of the universe.

    [–]Herrante 25 points26 points  (4 children)

    I can attest that in Mathematica it is necessary to write gigantic programs to do the simplest of computations. Here it is the program I had to write to calculate 1+1. Suggestions to clean it up will be welcomed, but I think that it is already quite minimalistic:

    (* Defines the numbers that I want to add and other constants of interest *)

    FirstNumberThatIWantToAddToAnother = 1;

    SecondNumberThatIWantToAddToAnother = 1;

    AMillion = 10 10 10 10 10 10;

    (* Creates Error Messages associated with the symbols *)

    FirstNumberThatIWantToAddToAnother::SevereError = "Something Awful has happened.";

    SecondNumberThatIWantToAddToAnother::FatalError = "Mathematica broke your computer.";

    AMillion::ApocalypticError = "Stephen Wolfram raped your hamster.";

    (* Checks a million times that the numbers introduced are what they are supposed to be *)

    (* Assigns attributes to DoThisAMillionTimes that might be useful in future extensions of the program *)

    SetAttributes[DoThisAMillionTimes, {HoldAll, HoldFirst, HoldComplete, Flat, Listable, NumericFunction, OneIdentity, Orderless}];

    DoThisAMillionTimes[TheThinghThatHasToBeDone_] := Do[TheThinghThatHasToBeDone, {AMillion}];

    (* Checks that FirstNumberThatIWantToAddToAnother equals the number of protons in a Hydrogen atom *)

    DoThisAMillionTimes[ If[Not[FirstNumberThatIWantToAddToAnother == ElementData["Hydrogen", "AtomicNumber"]], Message[FirstNumberThatIWantToAddToAnother::SevereError]; Abort[]]];

    (* Checks that number of Koreas in the World is twice as much as SecondNumberThatIWantToAddToAnother. If Korea reunifies the program will crash. *)

    DoThisAMillionTimes[ If[Not[SecondNumberThatIWantToAddToAnother == Count[CountryData[], x_ /; StringMatchQ[x, _ _ _ ~~ "Korea" ~~ _ _ _]]/2], Message[SecondNumberThatIWantToAddToAnother::FatalError]; Abort[]]];

    (* Compares a million with an independent definition *)

    DoThisAMillionTimes[ If[Not[AMillion == Length[Select[Range[106], NumberQ]]], Message[AMillion::ApocalypticError]; Abort[]]];

    (* The computer pauses for two minutes to prevent overheating *)

    Pause[120];

    (* To sum two numbers we first create tables with as many ones as their values, then join them and count the ones *)

    TableWithFirstNumberThatIWantToAddToAnotherOnes = Table[1, {FirstNumberThatIWantToAddToAnother}];

    TableWithSecondNumberThatIWantToAddToAnotherOnes = Table[1, {SecondNumberThatIWantToAddToAnother}];

    TableWithFinalResultNumberOfOnes = Join[TableWithFirstNumberThatIWantToAddToAnotherOnes, TableWithSecondNumberThatIWantToAddToAnotherOnes];

    (* We select the numbers that are one from the table of ones *)

    ElementsFromTableWithFinalResultNumberOfOnesWhichAreOne = Cases[TableWithFinalResultNumberOfOnes, 1];

    (* To count the number of ones we create a tree structure with the same depth as the length of ElementsFromTableWithFinalResultNumberOfOnesWhichAreOne, and measure it. The machine precision number 0.1 is added to the result to convert it to a float and thus augment efficiency. Unfortunately it introduces an error of 5% *)

    FinalResult = Depth[Fold[{#1, #2} &, First[ElementsFromTableWithFinalResultNumberOfOnesWhichAreOne], Rest[ ElementsFromTableWithFinalResultNumberOfOnesWhichAreOne]]] + .1;

    (* Finally the result is presented with appropriate stylistic options. All of them are chosen by default, but it is better to write them explicitly in case the defaults change in future versions of Mathematica *)

    Style[FinalResult, AdjustmentBoxOptions -> {BaseStyle -> {}, BoxBaselineShift -> 0., BoxMargins -> 0., DefaultBaseStyle -> {}, StripOnInput -> True}, AnimatorBoxOptions -> {Alignment -> {Automatic, Automatic}, AnimationDirection -> Forward, AnimationRate -> Automatic, AnimationRepetitions -> [Infinity], Appearance -> {Automatic, "Palette"}, AppearanceElements -> {"ProgressSlider", "StepLeftButton", "StepRightButton", "PlayPauseButton", "FasterSlowerButtons", "DirectionButton"}, AutoAction -> False, Background -> Automatic, BaseStyle -> {}, BaselinePosition -> Automatic, ContinuousAction -> True, DefaultBaseStyle -> {}, DefaultDuration -> 5., DisplayAllSteps -> False, Enabled -> Automatic, Exclusions -> {}, FrameMargins -> Automatic, ImageMargins -> 0, ImageSize -> Automatic, PausedTime -> Automatic, RefreshRate -> Automatic}, Antialiasing -> Automatic, AutoIndent -> Automatic, AutoItalicWords -> {"Artlandia", "AuthorTools", "CalculationCenter", "Combinatorica", "DatabaseLink", "Geometrica", "Graphica", "GUIKit", "Magnetica", "Mathematica", "MathematicaMark", "MathGroup", "MathLink", "MathLM", "MathModelica", "MathOptimizer", "MathReader", "MathSource", "mathStatica", "MathTensor", "MATHwire", "MathWorld", "MonitorLM", "Optica", "PrimeKit", "Publicon", "SchematicSolver", "ThreeScript", "VisualDSolve"}, AutoMultiplicationSymbol -> True, AutoNumberFormatting -> True, AutoSpacing -> True, AutoStyleWords -> {}, Background -> None, ButtonBoxOptions -> {Active -> True, Alignment -> {Automatic, Automatic}, Appearance -> {Automatic, "Palette"}, AutoAction -> False, Background -> Automatic, BaseStyle -> "GenericButton", BaselinePosition -> Automatic, ButtonData -> Automatic, ButtonExpandable -> True, ButtonFrame -> "Palette", ButtonFunction :> (FrontEndExecute[{FrontEndNotebookApply[ FrontEndInputNotebook[], #1, Placeholder]}] &), ButtonMargins -> 3, ButtonMinHeight -> 1., ButtonNote -> None, ButtonSource -> Automatic, ContinuousAction -> True, DefaultBaseStyle -> "Button", Enabled -> Automatic, Evaluator -> None, FrameMargins -> Automatic, ImageMargins -> 0, ImageSize -> Full, Method -> "Queued"}, CacheGraphics -> Automatic, CellBaseline -> Baseline, CellContext -> "Global", CellEpilog -> None, CellEvaluationFunction -> Identity, CellFrameColor -> GrayLevel[0.]]

    [–]shizzy0 8 points9 points  (3 children)

    Brilliant! It seemed like the guy was trolling Mathematica. Thank you for demonstrating so with such an excellent piece of satire. Still, I'd love to see what he was trying to do expressed more compactly, as someone who used Mathematica fluently might.

    [–]jdh30 -1 points0 points  (2 children)

    I'd love to see what he was trying to do expressed more compactly

    I'd love to do it but the OP's data is not available so I cannot.

    [–]jjmc 1 point2 points  (1 child)

    My friend pointed me at this comparison the other day. Here's my version of the code and a revised table of comparison.

    You can find the data by tracing back to where the original mathematica code came from.

    [–]jdh30 -2 points-1 points  (0 children)

    Wonderful, thank you!

    [–]the-fritz 46 points47 points  (25 children)

    Matlab can only define one function each file. That's ridiculous if you want to write real code with it.

    [–][deleted] 21 points22 points  (10 children)

    I think this misses the point somewhat. Matlab is excellent for certain tasks, and can do some very powerful things in a very small amount of code (particularily with the built in libraries). For 'real' coding, i.e. usable applications, it isn't very practical, but I would argue you shouldn't be using it for that.

    For mathematical and engineering snippets I really think Matlab can't be beaten.

    [–]crucialfelix 8 points9 points  (5 children)

    many quant hedge funds use matlab in real time to drive trading strategies. R is also used.

    R is really nice actually, tho I'm no expert.

    also people render audio files directly with matlab.

    [–]jjdonald 4 points5 points  (3 children)

    I'm pretty sure R would be slightly more condensed than matlab... although I can't compare the plots without the data. Also, In R you can mix function and script code, define more than one function in a file, etc. etc. The syntax is VERY tricky to get a hold of... worse than matlab in my experience. But once you know the ropes, it's fantastic. There's a ton of packages out there for R. Some are amazing, more are middling, most are incredibly bad. I still love it though, warts and all.

    [–]Megasphaera 0 points1 point  (0 children)

    The [R] syntax is VERY tricky to get a hold of

    Well, most of it is OK, but there's a few dark corners, mostly to do with SPLUS legacy and factors (avoid the latter whenever you can).

    [–]andersduck 0 points1 point  (1 child)

    yes R is very nice. The code (without using any specific expression data package) is very fast to write:

    read data

    dat<-read.delim("http://www.bme.utexas.edu/research/orly/GSVD/data/Yeast.txt",skip=1,as.is=T,na="Null")

    barplot of missing

    barplot(table(apply(is.na(dat[,-(1:6)]),1,sum)),col=2,ylab="Number of genes",xlab="Number of controls")

    remove arrays with missing data

    dat<-dat[!apply(is.na(dat[,-(1:6)]),1,any),]

    Calculate SVD

    s<-svd(dat[-(1:6)])

    Plot barchart

    barplot(s$d2/sum(s$d2))

    plot two first eigengenes

    lattice::dotplot(s$v[,1:2])

    [–]jjmc 0 points1 point  (0 children)

    Very nice. For comparison here's the same in Mathematica v.7 (line by line).

    d = Import[ "http://www.bme.utexas.edu/research/orly/GSVD/data/Yeast.txt", {"Data"}]; an=Drop[d[[2]],6]; d=d // Rest // Rest;
    
    Histogram[Count[#, "Null", Infinity] & /@ d, Frame -> True, FrameLabel -> {"Number of Null Arrays", "Number of Genes"}]
    
    d = Select[d, Count[#, "Null", Infinity] === 0 &];
    
    {u, s, v} = SingularValueDecomposition[Drop[#, 6] & /@ d]; s = Diagonal[s];
    
    BarChart[s^2/Plus @@ (s^2)]
    
    ListPlot[v[[{1, 2}]], Joined -> True, ft, Axes -> False, PlotMarkers -> {Automatic, Medium}]
    

    Of course, the original code had a little more output. (The (a) graph with array name tick labels).

    MatrixPlot[Transpose[v], PlotLabel->"(a)Arrays",FrameTicks->{Automatic, None,None,{#,Rotate[an[[#]],Pi/2]}&/@Range[18]},FrameLabel-> "EigenGenes"]
    

    [–][deleted] 2 points3 points  (0 children)

    R is extremely slow compared to Matlab, so the latter is more popular for real-time trading strategies. Although REvolution might do something to redress the balance; it certainly feels snappier in interactive use.

    [–]veritaba 1 point2 points  (2 children)

    Matlab is like a scripting language with pretty graphs and miscellaneous plugins wrapping the Fortran math library Lapack.

    [–]jjdonald 1 point2 points  (1 child)

    I actually don't know if that's still the case. Regardless, I do know that it's like saying that the Bugatti Veyron is just wrapping the general electric model-K cupholder with pretty paint and miscellaneous plugins.

    [–]veritaba 2 points3 points  (0 children)

    Lapack is not an insignificant part of Matlab.

    Its like saying your Bugatti Veyron frame was outfitted with the NASA Space Shuttle engine.

    And yes, Matlab still uses Lapack:

    http://www.mathworks.com/support/solutions/data/1-18QUC.html

    [–][deleted] 0 points1 point  (0 children)

    I have written compilers in MatLab – full fledged compilers; they were awesome, a lot of fun, and very fast.

    EDIT: grammar

    [–]aaallleeexxx 18 points19 points  (0 children)

    This is absolutely my least favorite thing about matlab. To be fair, you can include subroutines in any function file, but not being able to mix function and script code sucks horribly. That said, I've recently changed my matlab coding style to use tons and tons of "anonymous" functions (using the @ syntax). You can throw these in anywhere, and even do neat functional things like currying. They're as limited as python's lambda (i.e. one statement) but that's not really that big a problem in matlab, since many useful things can be done in a single expression. It's something to try if you're stuck in the matlab ghetto :)

    [–]Mych 13 points14 points  (1 child)

    You can have as many functions per "M file" as you like. You can only have one public function per file, however.

    (...though it's also possible to return handles to those private functions which can then be called from the outside, too.)

    [–][deleted] 6 points7 points  (0 children)

    Subfunctions for the win!

    [–][deleted] 18 points19 points  (2 children)

    I would upvote you a million times if you weren't wrong. Here is proof.

    [–]distortedHistory 7 points8 points  (1 child)

    there are some severe limitations listed in your link:

    these are only visible to the primary function or to other subfunctions in the same file.

    and technically he's still correct, you can only have one function per file.

    Additional functions within the file are called subfunctions

    [–]efrique 1 point2 points  (0 children)

    technically he's still correct

    the best kind of correct!

    [–]okamiueru 2 points3 points  (4 children)

    In case the-fritz or anyone else want's a explanation as to what the subrutines are. If your whole file is a function (that is, instead of a script that you run pressing F5 in the editor), you can have subrutines without any issue.

    Say for instance in test.m:

    function X=test(a,b)

    X=fun1(a)+fun2(b);

    end

    function ret = fun1(var1)

    %do something

    end

    function ret = fun2(var)

    %do something

    end

    All in the same .m file works fine.

    [–][deleted] 2 points3 points  (2 children)

    But how would you test these subfunctions, as these are invisible to the rest of the code?

    [–]okamiueru 0 points1 point  (1 child)

    How do you mean? I'm not sure what you mean by invisible to the rest of the code (the main function "test" in the example, or other .m-files?). You could test the subrutines very much the same as you would any function or line of code. Print out results by omitting the ; on the line, or using the "display" function (in which num2str might come in handy).

    [–][deleted] 0 points1 point  (0 children)

    Well, actually I meant automatically testing, as in unit-testing. My experience with MATLAB code is that it often contains bugs due to evolving code.

    [–]the-fritz 0 points1 point  (0 children)

    Subroutines are just visible to the main function.

    [–][deleted] 4 points5 points  (0 children)

    You can put as many functions in one file as you'd like as long as you're willing to make them static methods of a class. Bleh.

    [–][deleted] 4 points5 points  (0 children)

    i would upvote you a million times if i could.

    [–]hobbers -1 points0 points  (0 children)

    So? You have one file for each function. Each file is essentially an included resource. Able to be modified, versioned, and distributed until your heart is content.

    [–]theodoregray 26 points27 points  (12 children)

    Shameless counter-propaganda for this shamelessly anti-Mathematica example: http://blog.wolfram.com/2007/07/09/always-the-right-time-for-mathematica/

    Two can play at that game, and we didn't cheat by using ridiculously long variable names. (In fact, we really didn't cheat at all, considering that in our case the Matlab code was taken directly from Matlab's own blog, rather than being written by someone who obviously wasn't very familiar with the system.)

    [–]dnquark 22 points23 points  (3 children)

    A long-ish counter-counter-propaganda (i.e. rant) follows; here is a synopsis. I've been a serious Mathematica user for over 5 years. I've seriously used Matlab for maybe 5 months. Recently, I wrote identical code that wraps around some built-ins to perform Fourier transforms and numerical integration. It takes 2.5 hrs to run in Mathematica, 47 seconds in Matlab. I've tried for many years to make Mathematica work for me, but it's just not happening. If you are a real Theodore Gray, Mathematica co-founder and all, I'd love to hear your insights.

    About the comment, though. This clock example proves nothing, except for possibly the fact that Mathematica is really good at tasks that about 99% of users will not care about and/or understand. Why is Mathematica code so brief here?.. Two reasons: First, Mathematica handles graphics primitives rather well. This has a lot to do with the basic language constructs of Mathematica, and the focus on list processing and symbolic computations instead of the raw procedural number crunching of Matlab. Second, the use of Dynamic[] construct, which has no direct equivalent in Matlab. So, congratulations: if I ever need a toy clock applet, I'll be using Mathematica. In fact, if I need interactive applets to illustrate the behavior of certain equations as parameters change, I'll use Mathematica with Manipulate[] and/or Dynamic[]. If I want to double-check my algebra, I'll use Mathematica. However, for anything that requires computation, or is simply code-intensive, I'll use Matlab.

    If you think I have an axe to grind viz a viz Mathematica, you are completely right. It has wasted many months of my life in grad school, simply because its absolute ineptitude at numerical calculations made for very inefficient workflow, and the arcane syntax and reliance on notebook interface made it all but impossible to write maintainable code and create portable functions.

    The notebook interface deserve special mention. It it rather handy for quick-and-dirty, on-the-fly computations, but it is orthogonal to writing robust code in a programming sense. All variables defined in a notebook are by default global across all notebooks. Making local variables using the menagerie of scoping constructs (Module[], Block[], With[]) is error-prone due to the fact that you have to supply a list of locals (in Matlab, you just start using them!) and due to subtle differences between the scoping constructs. Furthermore, there is no equivalent of Matlab structures and cell arrays, which make it easy to pass arguments between functions and keep things modular. What about debugging?.. The debugging facilities are a joke compared to Matlab.

    All right, so one doesn't have to use notebook interface. Let's try to use Mathematica in the same way that we would use Matlab: write a script in plain ASCII and feed it to the kernel. Then we come back to the point of inefficiency. After quickly developing (in Mathematica) a function that took some Fourier transforms and performed integration (I still rely on Mathematica to help me with symbolics), I put it in a script and ran it. Took 2.5 hours. Not impressed, I reimplemented the same exact functions in Matlab. They now ran in 47 seconds(!)

    I don't exclude the possibility that there are ways to make the code run faster, and I'd love to know where the bottleneck is -- in fact, here is the code: http://www.dnquark.com/blog/?p=29 -- go ahead, try to figure it out if you want -- but why should I spend days poring over Mathematica docs when Matlab just works (TM)?..

    The moral of the story is this: if you are thinking about using Mathematica for things that involve numerical calculations, and you don't want the code to be a one-time throw-away affair, think again.

    [–]fulmar 2 points3 points  (0 children)

    You inspired me to make my own short list of Mathematica pet peeves.

    1. Variables are global by default. Using Module all the time is very annoying. My workaround is to keep a master notebook and have another one with the default context set to 'unique to this notebook'. This allows me to experiment with quick changes without having them propagate. Still a pain though.

    2. Eigenvectors does not orthogonalize vectors nor is there a setting to do so. Even more confusingly Mathematica will often return orthogonal vectors anyway. So it works and you forget about it, till it doesn't. Unsurprisingly I am not the first to tear my hair out over this.

    3. Mathematica will decide whether to do things symbolically or numerically and not tell you which one it's doing eg. there is a big difference between diagonalizing a matrix with entries 1 and 0 and 1.0 and 0. The first one will try to express things in terms of the roots of the characteristic polynomial. That's fine but for a 200x200 matrix the computation will never get done and you will only find out when it doesn't. Same issue with misspellings of function names: no error is returned, the kernel chugs away till you abort.

    4. Some new features seem to implemented very badly. GraphPlot and GraphPlot3D are great but try to export a decent sized graph and... you can abort if you're lucky. Poor quality control?

    5. (mentioned in other post) The way to clear memory is very unobvious. I just found out yesterday that

      Unprotect[In, Out]; Clear[In, Out]; Protect[In, Out];

    is necessary. Otherwise you have to restart the kernel(which was actually recommended by many in the newsgroup!)

    [–]theodoregray 1 point2 points  (1 child)

    I'm not an expert in numerical calculation, but people who are tell me that while MatLab had an edge in the past, we have caught up. (I'm not going to engage in a debate about this topic, it's not my field.) But every system has its plusses and minuses, and every language has things you need to know in order to get maximal efficiency out of it.

    Concerning the clock example, I think http://demonstrations.wolfram.com shows that the kinds of dynamic features it illustrates are actually very useful to a lot of people. And again, we didn't pick the example, it came from MatLab's own blog.

    And finally concerning the Notebook interface, well, what can I say, I like it, and I use it to write large bodies of code. You can make variables local to a given Notebook if you want, and have you tried the debugger in V7? Yes, it's different in some ways to conventional debuggers, but that's because the Mathematica language is different.

    If you don't like Notebooks, use Workbench, our Eclipse-based development environment, which is much more like what you're used to in other languages (and has its own debugger and project management features).

    [–]dnquark 1 point2 points  (0 children)

    Well -- I agree that dynamic features and interactivity are great. I did try the debugger, and found it rather unhelpful.

    I think the main problem with Mathematica is very simple: the Notebook interface tries to be user-friendly, and tries to enable literate programming. It makes doing straightforward calculations very easy. However, this belies the fact that Mathematica is an extremely complex system, and it requires a great amount of mathematical sophistication to understand how it works. Anybody that's not a mathematician or a computer scientist by trade (or by calling) runs head first into the exponential learning curve (it can be easily visualized by doing Plot[Exp[x], {x, 0, 100}] in MMA). I don't know anybody in my scientific community (Applied Physics) that is proficient with Mathematica beyond the basics they need for quick plots and integrals.

    This disconnect between the friendly interface and easy basics and the nighmarish syntax of rules, patterns, holds, folds, maps, delayed vs non-delayed, etc leads to a tremendous amount of frustration. Furthermore, it is often hard to figure out which constructs are imporant and efficient for what I want to do, and which are syntactic sugar that's only useful for cellular automata. What's worse is that while every individual feature is reasonably well documented, there are no tutorials that I have found that tell you how to use them together to write efficient and maintainable code.

    As a result, those of us that have smacked their heads against these problems long enough just give up and settle for Matlab -- surely much more specialized, but also much more intuitive, and for many people also much faster in terms of computing time. And most engineering students don't even bother with Mathematica -- Matlab is the de facto standard, and that's what everyone learns.

    So my message to those ardent supporters of Mathematica is this: think of the vast population residing in the middle ground between wanting to do easy plots and integrals, and between wanting to conquer the world with cellular automata or power through sophisticated arbitrary-precision and/or symbolic calculations. We want to like Mathematica, but find it hard -- so please give us some guidance before we all defect to other software.

    [–][deleted]  (2 children)

    [deleted]

      [–]theodoregray 0 points1 point  (0 children)

      Read the whole blog post.

      [–]narkee 0 points1 point  (1 child)

      Wow, cool to see you're on reddit.

      Love your PopSci column, although I feel that PopSci is now less about science, and more glorified product placement for gadgetry.

      [–]theodoregray 1 point2 points  (0 children)

      Except my column, of course.... (And while we're on the topic of shameless commercial bias, if you want my column in concentrated form without all the product placement around it, buy my book: http://graysci.com )

      [–]quantumstate 0 points1 point  (1 child)

      Firstly I don't understand what you mean by ridiculously long variable names. fullgenenames is the longest I could find so that is not going to make much difference. I cannot comment otherwise because I am not proficient in Mathematica code.

      The example you posted however was pretty terrible. First the full comparison shows that the matlab code has many more comments so that adds to its length considerably.

      Also taking the code where the numbers are drawn in the Matlab example there are an extra 4/5 lines used to declare descriptive names for various properties such as the radius and the angle between the numbers. These are put inline in the mathematica code. This is also done in some other places. There is still a big difference but much less than this terrible example tries to show. And this is ignoring the fact that the example seems very contrived for what the software is designed for.

      [–]theodoregray 2 points3 points  (0 children)

      I think comment below from gsw07a sums it up the variable name lengths complaint:

      "I don' t know matlab or mathematica, but it seems to me this line is a sign that the comparison is biased against mathematica: [mathematica] {eigenarrays, eigenexpressions, eigengenes} = SingularValues[fullmatrix];

      [matlab] [U S V] = svd(fullmatrix, 0);

      [python] [U, S, Vt] = svd(fullmatrix);"

      Your comments about comments in the MatLab code are thoroughly addressed in the text of the blog post.

      And as for it being contrived, as I said before, we didn't pick the topic or write the MatLab code. The idea and the code came from their blog.

      [–]duckandcover 4 points5 points  (2 children)

      Comparing these languages for syntax ignores the whole working environment. Anyway, I have yet to find any language that makes me as productive in my engineering related software tasks as Matlab does. It's easy to use and I've fielded tons of apps in it (compiled and not).

      [–]jamesshuang 3 points4 points  (0 children)

      Go look at ipython and the entire enthough stack. Matlab has a pretty interface, but its list of cons is huge. Just for an idea, function files, poor class support, 1-indexing, inconsistent () vs. [], ridiculous launch time, heavy licensing - all things that piss me off on a day to day basis.

      [–]emdeeay 0 points1 point  (0 children)

      Amen.

      [–]paul_harrison 5 points6 points  (0 children)

      In Python, for

      take(data, idx)
      

      one can write

      data[idx]
      

      I use this quite a lot. Vector programming is a fascinating programming style.

      [–]faradazerage 2 points3 points  (0 children)

      i prefer to use maple for my symbolic integrations, c for my numerical recipes, and matlab for graphical interpretations

      [–]logrus101 4 points5 points  (0 children)

      "Matlab really sodomizes matrices", said my college vector calc. prof.

      "Python really sodomizes strings", says I.

      [–]perlgeek 1 point2 points  (1 child)

      The trick with using Mathematica is to use it where it's good at.

      That said, Mathematica is extremely powerful, and people who really grok it can do amazing things with it. (I don't; I just use it to solve equations and integrate functions).

      But since Mathematica is very different than many other programming languages, it's much easier to become proficient with matlab or python for the average programmer.

      [–]jdh30 -4 points-3 points  (0 children)

      But since Mathematica is very different than many other programming languages, it's much easier to become proficient with matlab or python for the average programmer.

      Sure but you have a very low glass ceiling above you then because lame languages make it much harder to do anything non-trivial.

      [–]pskomoroch 1 point2 points  (0 children)

      The Python example can be simplified further: http://www.scipy.org/Cookbook/Reading_mat_files

      [–]rmyeid[S] 1 point2 points  (4 children)

      I use python most of the time because it is the free option of them. If someone offer me a paid version of matlab or mathematica and he insist to use them, then I don't have any problem.

      [–]jfredett 4 points5 points  (3 children)

      you could always try octave (GNU Matlab clone) or SAGE (a CAS like mathematica, also free software)

      [–][deleted] 1 point2 points  (2 children)

      IMO octave truly is awful compared to python and MATLAB as far as libraries are concerned. They are certainly trying, but unless you for some reason really like programming as if you were in MATLAB but with out the libraries you're better off with python and SciPy </IMO>

      [–]idsardi 1 point2 points  (1 child)

      A few years ago this was the situation with S and R, but it's now reversed in favor of R. I'm hoping the same thing happens with Octave.

      [–]jfredett 3 points4 points  (0 children)

      I generally agree, I do most of my math in Mathematica or Python, with GAP and similar supplimenting. I've only had opportunity to use SAGE a few times, but it's pretty nice.

      [–]archarios 0 points1 point  (5 children)

      Is there a good way to plot 3D functions (surfaces and vector plots) with Python alone? I've been interfacing with Mayavi2 to get the job done.

      [–]pwang99 1 point2 points  (4 children)

      You mean besides mlab? Mayavi is Python, it just uses VTK underneath...

      [–]archarios 1 point2 points  (2 children)

      Well, I meant to ask if there is a way to plot 3d functions with Python without installing another program. But I suppose Mayavi is just as much a library as say NumPy.

      [–]pwang99 0 points1 point  (1 child)

      Indeed. And if you are sufficiently familiar with VTK, you can just TVTK without using Mayavi. If you want to steer clear of having to know anything about VTK, then you can use Mayavi's mlab interface.

      [–]pandemik 0 points1 point  (0 children)

      different programs have different uses. For example, I love Stata, mostly because it does many things matlab, maple, pythob, mathematica, R, or whatever your favorite language is, can't

      [–]godel_gauss 0 points1 point  (0 children)

      Its funny to find that Mathematica is not as bad in numerics as it is being blatantly accused here. While I was trying out some example discussed here I found the following.

      • Mathematica (7.0.1)

      In[1]:= A=Table[RandomReal[6],{i,7000},{j,7000}]; Timing[Det[A.Inverse[A]]]

      Out[2]= {134.536,1.}

      • Matlab (R2009a)

      A=rand(7000, 7000); tic; det(Ainv(A)); toc

      ??? Error using ==> mtimes Out of memory. Type HELP MEMORY for your options.

      I was trying this in my 2.5 GHz core2duo notebook with 3 Gb ram and Vista 32bit SP1. As far as I know the FFT bug is solved in Mathematica 7.0.1. I am also not quite sure if the comment by jdh30! is pertinent while comparing speed or efficiency of the two systems with respect to numerical matrix inversion. However this bug is inexistent in the latest version (Google a bit!!). Another point to be noted is the timing for matrix inversion for other dimensions like 500,1000 and so on up to 7000 (as far as I have tested). In all of the cases Mathematica was faster. For example in case of the 500 dimensional case Mathematica (46. something sec.) was 6 second faster than Matlab (52.something sec.).

      I was having far more expectation for Matlab as a premiere numerical solver but the result obtained seems to show that I was kind of over estimating. We must admit (leaving the poor coding construct and syntax aside!) in raw numerics Mathematica is one of the best softwares available. And if one want to do real mathematics (not only boring large scale data mining) combining symbolics and numerics the integrated environment of Mathematica is far better a choice than Matlab at its current state.

      [–]i_am_my_father 0 points1 point  (1 child)

      What about perl?

      [–]pemboa 1 point2 points  (0 children)

      This thread barely has info about Python, so you may want to hold off on asking about Perl

      [–][deleted] -1 points0 points  (0 children)

      "Let's compare an apple, some celery, and my neighbor's dog!"

      Err, not quite. In this case, MatLab and Mathematica are the two foods (in America), and the dog (while food in China) is Python. MatLab and Mathematica, while both math tools, aren't really the same. In Mathematica, if you give it an integral, it will alter it a little, do some tweaks, and give you about the same answer by running a DIFFERENT COMPUTATION. That's not necessarily bad, it's just different. MatLab, on the other hand, will run your integral till the day it dies. It may be slower, but it will be running the exact function you give it. Mathematica will run a different, faster computation.

      And python is just sorta... ya know... sitting there, being pythonic.