Mac OS X for the volcano nerd
Mac OS X for the volcano nerd
Octave for scientific computing - Installation
I have been a reasonably heavy user of MATLAB® for the best of the past 10 years and have been relatively pleased with it till.... I switched to Mac a few years ago. To cut a long story short, MATLAB® does not run well under Mac OS X and even “incredibly slow” would be an understatement of its performance. Even worse, it simply crashes very often, which is a tad annoying when attempting to crush numbers for several days in a raw. The main issue on Mac OS X seems related to MATLAB® still running under X11. At launch time, the command window is also regularly plagued by numerous java errors which, while relatively harmless on themselves, are a blatant reminder that MATLAB® is not really working the way it should be.
One way that helped a bit was to run it from the terminal without the Java Machine by typing:
matlab -nojvm
However, this means not being able to get access to the graphical parts. Add this to the fact that MATLAB® is RAM hungry, that the export quality of figures is below par, that it is fairly expansive and that your institute may not have purchased the non-standard toolboxes that you desperately need (e.g. Compiler), it quickly becomes a total headache.
Recently, after a few days of intense testing and increased frustration, I reluctantly pondered about using another language altogether. Problem: a lot of my number-crunching scripts are in MATLAB® already and the perspective of rewriting them all in an alternative language did not appeal the least to me.
This is where the holy Open Source community comes in. There are a few options around of MATLAB®-like programming languages that wouldn’t require a monster of an effort to adapt existing MATLAB® scripts. The two main options that caught my desperate eye were Scilab and Octave. Both bear similarities but Octave seemed the closest to MATLAB®, which was really the main drive behind this quest for an alternative.
Octave is a high-end alternative to MATLAB®. It is free for all and supports an already impressive list of functions (some come by default and others with additional packages), including filters, FFT, interpolation tools, etc. It is also incredibly similar to MATLAB® (if not downright identical in many cases) which makes the switch a breeze. Scripts are even saved with the .m extension which sometimes makes the distinction virtually impossible.
What follows is a quick How-To install and get Octave up-and-running on Mac OS X. It’s been tested successfully on 10.5.8 and 10.6.X. There are several ways of getting Octave and the required graphics applications (e.g., through Fink). Here I chose to go for the binaries directly from the main sites.
Download and install
-Aquaterm (if not wanting to run the graphics through X11) or X11 (Developper Tools)
Now you need to make sure that Aquaterm is called from gnuplot for plotting. To do so, you need to create or adjust the GNUTERM environment variable. Edit your ~/.profile file and add the following line to it:
export GNUTERM='aqua'
Note: replace ‘aqua’ by ‘X11’ should you want more interactions with the plots and use X11 instead of Aquaterm.
Also, If you installed Octave from the dmg, you may need to add the path of the executable to the terminal (e.g. in your ~/.bashrc or ~/.cshrc). The standard path should be
/Applications/Octave.app/Contents/Resources/bin
Next time you open the terminal or source your .*shrc files, everything should be up and running.
Open the terminal and launch Octave by typing
octave
As you will notice, octave runs inside the terminal so there is no ipsy-fancy GUI starting up. But the functionality's all there.
As with MATLAB®, help for the functions can be found by typing
help thisweirdfunction
Let’s now run a short test:
tx = ty = linspace (-8, 8, 41)’;
[xx, yy] = meshgrid (tx, ty);
r = sqrt (xx .^ 2 + yy .^ 2) + eps;
tz = sin (r) ./ r;
mesh (tx, ty, tz);
You should now see the figure that appears at the top of this page. If you want to save the image as pdf, juste type
print -dpdf myimage.pdf
Those familiar with MATLAB® can appreciate the similarities with Octave. By looking at the figure in pdf, I was also quite impressed with its quality, which has also always been a downside of MATLAB®.
You may want to install some relatively common additional packages. To do so, go here to get an overview of the available packages. Then:
-Download the *.tar.gz file for the package you are interested in.
-Open a terminal and go to the directory where you saved the *.tar.gz file
e.g. cd ~/Downloads
and launch octave from the terminal.
-install the package by typing
pkg install mypackage.tar.gz
replacing mypackage.tar.gz by the name of the file you just downloaded.
Packages I would suggest to install:
time (requires the miscellaneous package)
signal (requires optim and specfun packages; useful filtering functions, including filtfilt)
plot
financial (useful time axes manipulations)
You can check anytime what packages are installed by typing in Octave:
pkg list
The only main downside of Octave and Aquaterm compared with MATLAB®, as far as I’m concerned, is the lack of interactivity with the figures. This can be significantly improved by using X11 instead of Aquaterm.
X11 vs. Aquaterm
I find Aquaterm more appealing visually in terms of graphics quality. The downside is that interaction with the plots is extremely limited. There are also a number of issues including axes labelling.
Personally, I tend to use X11 for most of my work in octave, especially data exploration since it allows one to rotate and zoom plots using the mouse.
Juste make sure that X11 is set up as the GNUTERM variable (or, in gnuplot, type ‘set term X11’). Also, you may need to launch X11 before starting Octave.
On the other hand, Aquaterm is ideal if you don’t want any interaction with the plots and/or don’t want to use X11.
In terms of information and support, there is a ton of online documentation and an active users community so any question is likely to have an answer already online.
One thing only to say: try it. It is quite likely that you won’t regret it.
Links and more information:
Octave project: http://octave.sourceforge.net
Octave online user manual: http://www.gnu.org/software/octave/doc/interpreter
Gnuplot: http://www.gnuplot.info
Aquaterm: http://aquaterm.sourceforge.net
Monday, October 26, 2009