tags:

views:

521

answers:

8

i am a engineering student and i have to do a lot of numerical processing, plots, simulations etc. The tool that i use currently is Matlab. I use it in my university computers for most of my assignments. However, i want to know what are the free options available.

i have done some research and many have said that python is a worthy replacement for matlab in various scenarios. i want to know how to do all this with python. i am using a mac so how do i install the different python packages. what are those packages? is it really a viable alternative? what are the things i can and cannot do using this python setup?

+3  A: 

Maybe you like sagemath, which 'combines the power of many existing open-source packages into a common Python-based interface'. Here is a feature tour.

The MYYN
A: 

Duplicate of this.

My sense is that for pure numerical/linear algebra computations and visualization Matlab is a slightly more consistent development environment. Numpy/Scipy/Matplotlib feel, to me, a bit haphazard. If you are building a full program -- to automate a system or display results on a webpage -- Python the advantage of being a real programming language first and foremost. But for interactive numerical processing I think Matlab still wins. The lack of element wise infix operators in Python is one small example (PEP 225). For statistical computing, data exploration and visualization, it is hard to beat R.

Tristan
Default for array operations in Numpy is elementwise... lack of operators for matrix multiplication is easily overcome by using dot() or matrix class if you have a lot of linear algebra (for matrix class normal * operator is matrix multiplication)
thrope
I agree that you can work around this, but for somebody who spends all day working with matrices these workarounds are not as nice as what matlab style languages offer. Especially in dynamic typed languages where I don't know whether an object is an array or matrix and thus don't know the meaning of *. Element and object wise operators are also useful far beyond matrix multiply. For instance element and object wise logical operators serve different purposes and addition operators that impose column conformability (as in Stata's mata language) are also helpful.
Tristan
+1  A: 

python(x,y) is quite powerful, but only for Windows or Linux so you'll have to use bootcamp or Linux. A more lightweight package for mathematics is Matplotlib, which basically adds plotting abilities to the Python language (better used together with IPython).

RedGlyph
+9  A: 

On a Mac the easiest ways to get started are (in no particular order):

  • Enthought Python Distribution which includes most scientific packages you are likely to need. Free for academic/non-commercial use.
  • Macports - up to date with latest releases, so sudo port install py26-numpy py26-scipy py26-matplotlib py26-ipython should get you started.
  • Scipy Superpack - script to install recent svn versions of all the important packages.

I've done exactly this (replace Matlab with Python) about 2 years ago and haven't looked back. The broadcasting in Python, more intuitive memory model and other Numpy advantages make numerical work a complete pleasure. Plus with f2py, cython it is incredibly easy to put inner loops in another language. This is a good place to start - other impressive pages to provide motiviation are PerformancePython and ParallelProgramming. Be sure to understand Pythons "variable is a reference to an object" semantics... after that adjustment everything is plain sailing. One of the coolest things that beats matlab is in 2 lines I run over 8 cores... p = Pool(8); res = p.map(analysis_function,list_of_data) - MATLAB parallels toolboxes are so expensive I've yet to see a University that actually has them.

thrope
You may also want to install the developers tools; various modules do need the gcc compiler and make to install.
extraneon
"MATLAB parallels toolboxes are so expensive I've yet to see a University that actually has them." Actually the Parallel Computing Toolbox is just a standard toolbox and all of the university site licenses I've used include it. If you're talking about the Distribute Computing Server - then you're absolutely right that it's expensive, but you don't need it to run on 8 local cores.
Ethan White
I stand corrected - I thought it was more expensive. Still not seen it in the UK though. To give you an idea at my top 10 >25,000 student university we have _2_ optimization toolbox licenses! We had a new computer suite for an MSc course of about 10 computers - I looked at getting DCS and the cost in total was 3 x the cost of the hardware.
thrope
Ouch! That's rough. The cost of DCS is part of the reason I've started learning Python for some of my groups bigger projects. Overall great answer by the way. Enthought looks very handy (too bad the 64-bit version isn't freely available for academics).
Ethan White
A: 

Try Ubuntu Linux. Install it on your Mac, I have it on all my Macs. Ubuntu has all required packages to work with numerical math and visualization. Then, you will need to install only 2 packages:

1) Install SciPy. It is open-source software for mathematics, science, and engineering. It includes a lot of stuff, e.g. matplotlib, which is a python 2D plotting library which produces publication quality figures in a variety of hardcopy formats and interactive environments across platforms.

2) Install ipython. It has enhanced interactive Python shell.

In order to install them, you can use a simple shell command in the Terminal:

aptitude install  python-scipy ipython

Remember, that all these programs are in the very intensive development and thanks to Ubuntu's Software Update you will always have all it up-to-date without reinstalling it.

psihodelia
That’s not a real option unless it was specifically asked for another operating system or there is no other way around doing so.
Debilski
It can be done, but the python environment on Apple is first-rate if you have installed gcc from the developers tools. So it isn't really necessary.
extraneon
-1 - OS X is actually one of the best platforms for scientific computing. It's the easiest platform (by far) to build numpy/scipy by hand (due to standard Accelerate framework) and with macports you get exactly the same one line install advantage. Also Scipy doesn't include matplotlib - its a seperate package that wouldn't be installed by your command above.
thrope
+1  A: 

Try Sage - it is designed as an open source replacement for Matlab, Mathematica etc. It is implemented in Python and can be scripted with Python, but it also adds a lot of maths-specific features. There is an installer for the Mac, so you will not need to download lots of individual packages.

There is also GNU Octave - another open source alternative to Mathematica/Matab that has its own programming language. However I have not found any information on a Mac version (though I have not looked very hard).

Dave Kirby
+6  A: 

I've been programming with Matlab for about 15 years, and with Python for about 10. It usually breaks down this way:

If you can satisfy the following conditions: 1. You primarily use matrices and matrix operations 2. You have the money for a Matlab license 3. You work on a platform that mathworks supports

Then, by all means, use Matlab. Otherwise, if you have data structures other than matrices, want an open-source option that allows you to deliver solutions without worrying about licenses, and need to build on platforms that mathworks does not support; then, go with Python.

The matlab language is clunky, but the user interface is slick. The Python language is very nice -- with iterators, generators, and functional programming tools that matlab lacks; however, you will have to pick and choose to put together a nice slick interface if you don't like (or can't use) SAGE.

I hope that helps.

reckoner
Agree with everything. Would add if you need things like non-double sparse matrices (which matlab doesn't support), memory mapped files, low level control of memory (when things are copied etc.) go with Python. I think nice interfaces for Python are starting to show up now the scientific stack is starting to stabalise - see for example http://code.google.com/p/spyderlib/ - and I expect them to improve rapidly in the next couple of years.
thrope
A: 

It would be great if the matlab to python conversion mat2py project at sourcefourge took off..

Fredriku73