Archive for October, 2007

October 31st, 2007

Imagine that you have a function of the form z=f(x,y) and you want to plot it. The result you have in mind is something like this:

The above plot was produced by Matlab and the scale on the right hand side is produced via the colorbar function. I was recently asked if it is possible to easily produce such a scale using Mathematica and after a long search through the documentation the answer was no! Just to make sure that I hadn’t missed something I made a post to comp.soft-sys.mathematica to see what the Mathematica gurus there would make of the problem.

Sure enough there is no simple alternative to colorbar in Mathematica but some helpful soul posted a piece of code that reproduced a similar effect. With a bit of work this turned out to be sufficient for the needs of the person who originally approached me and everyone was happy.

A few days later I discovered that someone called Will Robertson had been following the same thread on the newsgroup and he had used the information posted there to produce a package that allowed a Mathematica user to easily produce ‘colorbar plots’ for both DensityPlots and ContourPlots. I hacked his code so that it supported Plot3D as well and emailed it to him. Between us we tidied up the code a little and submitted it to the wolfram library for everyone to download and use for free.

There is an examples file included in the package distribution that shows how to use it in detail but to give you an idea of what you are going to get here is how to plot the function

 \light z=e^{-x^2-y^2}

once you have downloaded and run the package. The command

ColorbarPlot[Exp[-(#1^2 + #2^2)] &, {-2, 2}, {-2, 2}]

produces the following plot

The above plot is a DensityPlot which is the default type but you can change it using the PlotType option:

ColorbarPlot[Exp[-(#1^2 + #2^2)] &, {-2, 2}, {-2, 2},PlotType->ContourPlot]

Valid PlotTypes are DensityPlot, ContourPlot and Plot3D but this list will be expanded in future versions. Finally, here is a plot that makes use of lots of options.

f = Exp[-(#1^2 + #2^2)] &
plot = ColorbarPlot[f, {-2, 2}, {-2, 2},
PlotType -> Plot3D,
XLabel -> “x”,
YLabel -> “y”,
ZLabel -> “z”,
Title -> “Gaussian”,
CLabel -> “Range”,
Height -> 300,
Colors -> “TemperatureMap”,
Boxed -> False

The package is available for download from here. Comments are welcomed and we hope you like it.

  • UPDATE 12th Novermber 2010. Update to version 0.6
  • UPDATE 22nd October 2009. Update to version 0.5
  • UPDATE 5th June 2008. This package has now been updated to version 0.4
October 23rd, 2007

I don’t know very much about PHP. In fact it is probably more accurate to say that I don’t know anything about programming in PHP and yet, earlier today, I found myself in need of being able to type in simple PHP scripts and run them on the command line. A quick google search later and I find that I need to issue the following command in Ubuntu

apt-get install php5-cli

Now I can write little scripts like this one (which I called md5.php) and run them on the command line

#!/usr/bin/php -q
echo md5($arg),"\n";

./md5.php hello

I mention it because I might forget about it and looking up on here is quicker for me than googling it.

October 18th, 2007

UPDATE – 4th February 2010

This package gets downloaded from this website many times a month and I’m really pleased that it’s helping people out.  If you try it on your device then please consider dropping me a comment saying which device you are using and if it worked or not – it might help other users out there.

Thanks – Mike.

UPDATE – 20 March 2008

It seems that pocket console website is with us no more and so it can be difficult to find both pocket console and pocket cmd on the web. In order to help people who are still looking for them I have uploaded both packages here in one zip file but first, a disclaimer:

I didn’t write this software, I don’t support it and I won’t help you fix it if it goes wrong. If your PDA or phone gets bricked as a result of using it then its not my fault – all I am doing is making an old set of packages available for those who want them. They work fine for me – that’s all I know about them.

So…with that said – here they are. Comments (as always) are welcomed.

Pocket Console (link dead as of March 2008) is a very nice piece of software that provides a console device for windows mobile systems. Combine it with PocketCmd (link dead as of March 2008) and you can control your windows mobile device from the command line – truly geek heaven!

Some of you may be wondering “why bother?” The correct geek response to this question is usually something along the lines of “because I can” but this particular pair of applications have a few other tricks up their sleeves.

Once you have installed the base packages you can install some other, rather more interesting applications. For example – how about a pocket version of the computer algebra system PARI/GP? You can download the windows mobile version from the same site as pocket console – unfortunately it is not the latest version but it is still nice to play with.

If that is not enough for you then how about a pocket version of Yet Another Computer Algebra System (YACAS). I’ll be honest and say that I am not sure if YACAS needs pocket console as all of the instructions are in german and I only attempted to install it after I installed pocket console. It works just fine but since all of the messages are in German it looks like I am going to have to brush up a little on my modern languages.

There are also some non-maths applications on the pocket console website that make use of the application such as tetris, Star Trek and telnet but I have not tried any of them as they are not really my sort of thing.

So is installation straightforward I hear you ask? Well…sort of. I installed pocket console on a windows mobile 6 platform (The HTC Tytn II) and there are one or two issues you need to be aware of for this platform. The first is that you need to modify the following registry entry on your pocket pc


and change it’s value to 0 (This information came from here). I use the excellent freeware package, PHM Regedit to modify the registry on my device. Please note that modifying the registry can mess up your device if you are not careful so tread with caution!

On my machine I also had problems if I installed Pocket Console and Pocket CMD to a memory card. I received the following error message

“CMD Cannot start. There are too many console windows open. Please close some console applications and try again.”

I got around this by installing them to internal memory rather than a memory card – they are quite small so this is no big issue. I could install Pari/GP and Yacas to the memory card without any problems though. The only problem that remains is that now I get a couple of console messages pop up when I reset my device. Once I have closed them they don’t pop up again until the next resest so its no big deal.

If anyone out there knows of any other Windows Mobile applications that make use of Pocket Console then please let me know.

October 16th, 2007

During a routine google search I hit upon the following website which is a snapshot of Wikipedia taken in December 2001. For better or worse, the wiki is used by millions of people today and I think it’s fascinating to see what it looked like back in the early days.

October 16th, 2007

Life has been very hectic for me recently so I didn’t get chance to mention this at the correct time. The 18th Carnival of Mathematics was published on October 6th including over 50 maths-related posts. Ten days later and I still haven’t had chance to read them all!

The 19th Carnival will be up very soon over at Good Math, Bad Math.

October 1st, 2007

At the moment I am writing an introductory Mathematica course and was recently looking for inspiration for potential exercises. One website I came across (I have lost the link unfortunately) suggested that you get something interesting looking if you plot the following equation over the region -3<x<3, -5<y<5. It also suggested that you should only plot the z values in the range 0<z<0.001.

\light f(x,y)=e^{-x^2-\frac{y^2}{2}} \cos (4 x)+e^{-3 \left((x+0.5)^2+\frac{y^2}{2}\right)}

Suitably intrigued, I issued the required Mathematica commands and got the plot below which spoke to me in a way that no equation ever has before.

So now I have a question – What other messages could one find hidden inside equations like this? For example, is it possible to generate a three letter word with a relatively simple equation such as the one above? Of course if you were allowed to use very complex equations (and make use of Fourier transforms maybe) then I guess you could spell out whatever you choose but that’s no fun.

If anyone finds other such messages in simple(ish) equations then please let me know.