## Does MATLAB suck on OS X?

May 27th, 2009

I recently helped someone install the new 64bit beta version of MATLAB 2009a on a dual quad core Mac pro and so far he seems very pleased with it.  The 32bit version simply didn’t cut it because he needed to be able to access huge amounts of memory.  More and more researchers at my University seem to be choosing Mac Pros over other platforms and yet it seems that the MATLAB experience on them is far from perfect (according to this link at least).

People seem to complain that its slow compared with other operating systems on comparable hardware along with a clunky user interface since it uses X11 rather than Cocoa.

I’ll lay my cards on the table – I’m not a major Mac fan – but when so many people, who’s judgement I respect, choose them over other platforms then I sit up, take notice and try to understand.  Does anyone reading this have experience with MATLAB on OS X – favourable or otherwise?

## Supercharge MATLAB with your graphics card?

May 26th, 2009

Did you know that your graphics card is effectively a mini-supercomputer?  Your main CPU (Central Processing Unit) probably has 2 processor cores, 4 if you are lucky but a high end graphics card can have as many as 96 GPUs (Graphics Processing Units) – which is a lot.  Even my laptop’s relatively low end NVIDIA GeForce 8400MS has 16 ‘stream processors‘ according to this Wikipedia page.

The large number of cheap processor cores is the good news.  The bad news is that they are not as capable as fully fledged Intel or AMD processor cores since, as you might expect, the cores in your graphics card are rather specialised.  They were designed specifically to do the mathematics behind graphics processing and they do this very well indeed but until fairly recently it was rather difficult to get them to do much else.

That hasn’t stopped people from trying though. Some time ago,NVIDIA, the makers of my laptop’s graphics card, released a software library called CUDA which enables C-programmers to access the vast computational power locked away in a typical pixel pusher.  The results have been nothing short of astonishing.  One developer, for example, recently demonstrated how to use CUDA to calculate the properties of the Ising Model (A staple in undergraduate computational physics courses) over 60 times faster than a single, bog standard Intel CPU.

If you are impressed with a factor-60 speed up then the 675 times speed up reported by Michał Januszewski and Marcin Kostur is really going to knock your socks off.  Yep – that’s not a typo.  They have written code that can solve certain Stochastic Differential Equations SIX HUNDRED AND SEVENTY FIVE TIMES FASTER than a single, standard CPU core.  Your shiny new dual quad-core workstation isn’t looking so clever now is it?  Not bad for technology designed for playing the latest version of quake on.

This is all well and good but I don’t have the time or the mental stamina to code in C anymore.  What I want is for all of my favourite Mathematica, MATLAB or Python functions to be CUDA-ised so that I can enjoy a big speed up at low cost and low programming effort.  I’ll take the moon on a stick while I’m at it if you don’t mind.

Well, it seems that some people are doing exactly this.  I have just stumbled across a project called GPUmat which claims to offer up to 40x speedup with very little effort on the part of the user.  One example they give considers the following standard MATALB code.

A = single(rand(100)); % A is on CPU memory
B = single(rand(100)); % B is on CPU memory
C = A+B;    % executed on CPU.
D = fft(C); % executed on CPU

To get this running on your graphics card all you need to do is (after you’ve installed the toolbox and CUDA of course)

A = GPUsingle(rand(100)); % A is on GPU memory
B = GPUsingle(rand(100)); % B is on GPU memory
C = A+B;    % executed on GPU.
D = fft(C); % executed on GPU

Very nice. I’m not sure what MATLAB functions are supported but I guess it’s all there in the documentation – I just haven’t had time to look through it. I’d love to tell you what sort of speed-up I experienced when I tried it out but, unfortunately, the developers are asking for all potential users to register before they get access to the downloads and that put me off a bit

It’s all free though so if you’d like to check it out yourself, and you don’t mind the registration, then head over to the developer’s website. I’d love to hear how you get on.

PS: Make sure your graphics card is CUDA compatible first though.  You’ll waste a lot of time trying out this software if it isn’t!

## Getting useful data out of Wolfram Alpha can be difficult

May 22nd, 2009

Up until now I have been using Wolfram Alpha as the ultimate geek toy and have been truly delighted with it but I thought it was high time I tried to consider how one might use it more seriously.  So I set myself a task.  Nothing too complicated you understand , after all I am still finding my feet with this new system, but something that may at least possibly come up in the real world.  The task I set myself was

Obtain the actual data points for the Gross Domestic Product (GDP) of the UK from 1970 to 1980 inclusive.  To allow me to import this data into pretty much every analysis program on the planet I’ll want it in a CSV file of the form

1970,GDP of UK for 1970
1971,GDP of UK for 1971
etc

Should be easy huh?  Wolfram Alpha knows all about the GDP of the UK – if I Wolf GDP UK then I get the following output among other things).

Fabulous! The data is clearly in there but how do I get it out in the form I want? Let’s try the hopeful UK GDP from 1970 to 1980.  Alas I get the now familiar ‘Wolfram|Alpha isn’t sure what to do with your input.’ Moving on, I tried UK GDP 1970 to 1980 and UK GDP 1970-1980 but they didn’t work either.

I can get at a single datum easily enough.  UK GDP 1970 gives me 123.7 billion for example but how do I get it to give me a list?  Further experimentation showed me that I can get the GDP for any two years if I Wolf for something like (UK GDP 1970) (UK GDP 1971).

By now I feel I am getting somewhere. While playing with Wolfram Alpha (and reading the community forum) I’ve discovered that it will sometimes parse Mathematica code as well as plain English. ‘What I need‘, I thought, ‘is a piece of Mathematica code that would generate the query for me‘. So I tried

Table[“(GDP UK ” <> ToString[x] <> “)”, {x, 1970, 1980}]

but that didn’t work but then I shouldn’t be surprised because Table turns out to be one of the Mathematica functions that Wolfram Alpha doesn’t parse. Ho hum…

I tried a LOT of different inputs but the practical upshot is that the only one that worked was (UK GDP 1970) (UK GDP 1971) (UK GDP 1972) (UK GDP 1973) (UK GDP 1974) (UK GDP 1975) (UK GDP 1976) (UK GDP 1977) (UK GDP 1978) (UK GDP 1979) (UK GDP 1980).  Lord help me if I wanted three times as many data points.

For the record I can get exactly what I wanted in Mathematica 7 with the following two lines of code and I worked out how to do it with a moments thought.  Wolfram Alpha needs to be this easy!

data = Table[{x, CountryData["UK", {"GDP", x}]}, {x, 1970, 1980}];
Export["GDP.csv", data]

So, after some blood sweat and tears I had some actual numerical data but how could I export it to something useful.  Wolfram Alpha always returns results as images by default.

Which are not particularly useful if you want to do your own analysis.  I can also get it as copyable plaintext and for this data set it looks like this

$123.7 billion per year (US dollars per year) |$139.9 billion per year  (US dollars per year)
|  $160.8 billion per year (US dollars per year)|$181.5 billion per year  (US dollars per year)
|  $196 billion per year (US dollars per year) |$234.4 billion per year  (US dollars per year)
|  $225.2 billion per year (US dollars per year) |$254.4 billion per year  (US dollars per year)
|  $322.3 billion per year (US dollars per year) |$418.9 billion per year  (US dollars per year)  |
\$537.2 billion per year  (US dollars per year)

Hmmm. That’s going to need some pre-processing before I can import it into Excel I think – a job for a student or a Python script I think.

Now onto the Source information. It listed it’s primary sources as ‘Wolfram Alpha Curated data 2009’ and ‘Wolfram Mathematica CountryData’ with a shed load of Secondary sources such as ‘The US CIA WorldFactbook’. I have to say that I was a little surprised at this – how is Wolfram Alpha the Primary source of this data set? They must have got it from somewhere and THAT somewhere would be the primary source (or closer to it at least) IMHO.

In all honesty, I feel that putting itself as the primary source for data such as this is a bit like a student writing an essay and under ‘references‘ simply putting ‘My head‘.

Don’t get me wrong, I am starting to love Wolfram Alpha and think it’s got amazing potential but when you love someone you always want to see them do better for themselves.  In this particular area I think that Wolfram needs to address the following

• Make it easier to get lists of data out of WA. Being able to parse Table[] might be a good start
• Allow export of tabular data in popular formats such as CSV and Excel.
• Work on the sources information a little.  Wolfram Alpha didn’t actually generate this GDP data – they must have got it from somewhere and that should be listed as primary source.

Wolfram Alpha is a constantly moving target and it is quite possible that all of these issues will be addressed in no time (if Wolfram agrees that they are issues of course) so feel free to point out if any of the inputs I have linked to give different results from those stated here.  I am also aware that I don’t know everything about this system so if I am being an idiot then feel free to point out how I should have phrased my query.  Finally, if any new functionality comes online that makes all of this trivial then I would love to know.

## Slow symbolic toolbox startup in MATLAB 2009a

May 21st, 2009

One of the many jobs that I have to do is to package a version of MATLAB for distribution to my employer’s standard student Windows desktop image and so I got to test MATLAB 2009a on Windows for the first time.  While testing the deployed version of MATLAB I discovered that it seemed to hang when you tried to initialise the symbolic toolbox.

For example, typing

into MATLAB should start the mupad notebook but it just sat there for over 10 minutes before I got bored and terminated the process.  Similarly, if you type

syms x

to set the variable x as a symbolic variable then it just seems to hang.  At first I thought there was something wrong with my deployment method but it turns out that it’s a bug in MATLAB 2009a.

Happily, it’s a bug that Mathworks knows about and they have provided a workaround.  Unhappily, you need to regsiter for a Mathworks account to get access to the zip file containing the workaround.

## Kiss, love and flirt around with Wolfram Alpha

May 20th, 2009

An algebraic surface is a set of solutions to the general equation f(x,y,z)=0 where f is a polynomial in the variables x,y and z.  For example if you set f to the following polynomial

then the set of points x,y and z that satisfy f(x,y,z)=0 forms a sphere of radius 1.  You can get much more interesting surfaces than a sphere though.  For example, set

and you’ll get something known as the kiss surface – so called because the bottom section resembles a Hershey’s Kiss. Wolfram Alpha knows all about this surface and if you wolf Kiss Surface you’ll get a whole load of mathematical information about it along with the plot below.

One algebraic surface I have looked at in the past is the Heart Surface and it’s pretty obvious to see where it gets its name from.

At the time of writing, Wolfram Alpha knows about 129 different, named algebraic surfaces but for some of them it can be a little harder to work out how they got their name. Does anyone know why the one below is called the Flirt Surface for example?

Other interesting ones have names like Heaven and Hell,Citrus, Star and Plop!

This functionality is very nice indeed but for it to be really impressive I’d like to see a bit more (I wouldn’t be me if I didn’t want more). For example, it would be great if I could rotate each surface with the mouse – just as I can with 3D images in Mathematica. I’d also like to see more information on each surface such as how it got it’s name or the Mathematica code needed to produce the plot.

What’s your favourite algebraic surface and what extra functionality would you like to see in this area?

## Use Wolfram Alpha to lose weight.

May 18th, 2009

I apologise to any of my regular readers who may be tired of all of the Wolfram Alpha updates but I am pulling an all-nighter at the office and whenever I find myself waiting for my main computer to finish what it is doing, I end up feeding queries to Wolfram Alpha.

From the beginning, I knew that Wolfram Alpha knows about the calorie content of a lot of foods.  If you walpha snickers bar for example you get quite a lot of information including the following.

OK, so you are on a diet and you’ve just given in and eaten a snickers bar. Now you have calorie guilt and you want to know how much you have to run to burn it all off and break even. Walpha the term exercise calories burned and you’ll get quite a large set of results including a set of editable input boxes similar to the screenshot below.

The input parameters refer to my run on the treadmill yesterday and I see that I burned 408 Calories according to Wolfram Alpha. Actually this is in complete agreement with the readout on the treadmill so whatever model they are using – they agree with each other.  Put another way, my 5km run is worth almost one and a half snickers bars.  On reflection, however, maybe I need to lay off the snickers bars because Wolfram alpha also tells me that my body mass index is a little on the high side. Ho hum….

What I find cool about these input boxes is that you can use any units you like.  I used kilometers per hour but could have chosen miles per hour or a pace of 8 minutes per mile.  Heck, I even put my height in parsecs and it just got on with the calculation. Wolfram Alpha also has a guess at how quickly I might run a marathon based on my current fitness using the Riegel and Cameron models.  I’ve never run a marathon so couldn’t possibly comment on its accuracy.

## When will you be one billion seconds old?

May 18th, 2009

Give or take a few hundred seconds I will be 1 billion seconds old on September 2nd 2009 and there will be a celebration :)  Using Wolfram Alpha you can easily find out when you will be (or were) 1 billion seconds old simply by doing a query like

1 billion seconds from 18 May 2009

I’m going to have to try really hard to stop Walking Randomly from becoming a blog about Wolfram Alpha but I really am enjoying playing with this system.

## Plotting Fractals with Wolfram Alpha

May 18th, 2009

I saw a tweet from someone this morning which mentioned that you could plot the Julia Set using Wolfram Alpha.  I had to try this for myself as soon as I could and, sure enough, you can plot the Julia set for any complex number Z: -0.765+0.003 I for example.

Very nice but what else can it do.  If I Walpha fractals then I get the following output so I’d expect Wolfram Alpha to compute at least the Koch snow flake, the Sierpinski gasket, the Haferman carpet and the curlicue fractal and, sure enough, it does (click on the links to see for yourself)

Here is a screenshot for the Koch Fractal.

These aren’t the only fractals it knows about though. If you walpha Pentaflake (a fractal close to my heart) then you get the following.

Wolfram Alpha can also calculate the H-Fractal.

Cantor dust is in there too

as is the box fractal

It also looks like they are in the middle of implementing the Cesaro fractal.  If you walpha the term then it tries to generate the fractal for a phase angle of pi/3 radians and 5 iterations.  A few seconds later and the calculation times out.  If you lower the number of iterations it returns a red box such as the one below.  If my memory serves, Mathematica returns such a box if there is a problem with the graphics output.  I hope to see this fixed soon.

Update:15th July 2009 – The Cesaro Fractal has now been fixed)

It also seems to know about the following fractals but doesn’t seem to calculate anything for them (yet).  I say that it seems to know about them because it gives you an input field for ‘Iterations’ which implies that it knows that a number of iterations makes sense in this context.  It’ll be cool to see all of these implemented in time.

(Note: None of these are implemented yet and may never be – I’ll update if that changes)

• Menger Sponge Update 21st December 2010 – this has now been implemented
• Gosper Island Update:15th July 2009 – this has now been implemented
• Apollonian Gasket Update 21st December 2010 – this has now been implemented
• Dragon Curve Update 21st December 2010 – this has now been implemented
• Hilbert Curve Update 21st December 2010 – this has now been implemented
• Peano curve Update 21st December 2010 – this has now been implemented
• Cantor Set Update:15th July 2009 – this has now been implemented

Some odd omissions (at the time of writing) are the Mandelbrot set (Update: 15th July 2009 – this has been done now) and the Lorenz attractor.

This is all seriously cool stuff for Fractal fans and shows the power of the Wolfram Alpha idea.  Let me know if you discover any more Fractals that it knows about and I’ll add them here.

Update: I’ve found a few more computable fractals in Wolfram Alpha.  Please forgive me for the lack of screenshots but this is getting to be a rather graphic-intensive post.  The links will take you to a Wolfram Alpha query.

## ‘To Walpha’ – a new verb for searching?

May 18th, 2009

I was geeking out majorly yesterday while watching the new Star Trek movie with some friends and we got around to discussing Wolfram Alpha a fair bit (well, I was doing most of the talking to be honest – I’d had a LOT of coffee).

As I was explaining what it could and couldn’t do – I found myself saying ‘if you search for XYZ on Wolfram Alpha then..’ a lot and it quickly got old as it was nowhere near as succinct as ‘if you google XY then…”.  It wasn’t long before I found myself saying ‘If you Walpha XYZ then…’ and no one pulled me up on it.  Rather than saying ‘What the hell are you talking about…there is no such word as Walpha.’ – my friends uncounciously started using the term themselves.

Wonder if it will catch on?

## Wolfram Alpha has an API

May 16th, 2009

If you are a developer and want to get your hands dirty with Wolfram Alpha – here is a link to the API documentation:

http://www.wolframalpha.com/developers.html

Not had chance to read it myself yet (in the middle of cooking for a dinner party) but would be interested in people’s thoughts.