## Simulating Harmonographs

August 30th, 2008

“Do you like pendulums?” I was asked, “because if you don’t like pendulums then I wouldn’t bother with A-Level physics if I were you.” This was the advice given to me by an outgoing sixth-former at a school open day around 14 years ago. He had obviously had an unhappy time during his physics studies and was doing his best to turn me away from the subject but he hadn’t counted on the fact that I actually do like pendulums. Besides, I figured that high-school physics isn’t only about pendulums – they’ve got springs too!

Of course everyone knows what a pendulum is – thing that swings back and forth, used in grandfather clocks. When all is said and done, you might argue that pendulums are simple, sometimes useful and, above all, dull. My sixth-form friend certainly thought so but maybe that was because he didn’t have enough pendulums!

One pendulum is useful but two are much more interesting and four can be downright fun! The Victorians certainly thought so and over 100 years ago they used to build home entertainment devices out of pendulums called harmonographs. You have probably never heard of a harmonograph (I certainly hadn’t until a couple of days ago) and so maybe a bit of detailed explanation is in order.

Imagine that you have attached a pencil to a pendulum so that it brushes across a piece of paper as the pendulum swings back and forth. When the pendulum finishes swinging you will end up with a single straight line drawn on your paper – very dull indeed! Now imagine further that you somehow manage to connect a second pendulum to your pencil which oscillates at right angles to the first. The resulting drawing might look something like the image below. If your imagination fails you (or if my explanation isn’t up to the job) then you can see a video of the set up I am trying to describe by clicking here.

Alternatively, you could have one pendulum attached to the pencil and another attached to the drawing surface as in the example below.

There are many different designs for harmonographs and some manage to incorporate up to 4 different independent oscillations by attaching pendulums to the drawing surface as well as the pencil itself. The resulting drawings can be spectacular.

So how might we go about simulating a harmonograph? Well the motion of a single damped pendulum along the x axis can be described by the parametric equation

where t denotes time, p is a phase factor between 0 and 2*pi and d is the strength of the damping term. The larger you make d, the more quickly the pendulum oscillations will decay.

If we have two independent pendulums oscillating along the x-axis, both contributing to the overall motion of our pencil then, thanks to the principle of superposition, the total motion along the x-axis is given by

If we also have two pendulums oscillating along the y-axis then the final set of equations is

Now, if you search the internet you will find that other people have written down equations for harmonograph plots and you might find that they look slightly different to the ones I have written above but you should always be available to transform my equations into any other valid set. For example, the equations given in the website here describe a system with only three pendulums so simply cross out the second term for y(t) in my set of equations and you are almost done. You might also find that some people use Cosine instead of Sine – in which case you simply set the phase in my equations to be pi/2 since sin(x+pi/2) = cos(x).

Something else I have done is to assume that the initial amplitude of all of my pendulums is set to one. This is because I already have 12 parameters to play with which I think is more than enough for an initial play around.

As an aside, it turns out that these equations can describe much more than just Harmonographs. For example, by setting the damping factors to 0 and by crossing out the second term in each equation (thus only considering 2 oscillators) you will end up with Lissajous figures. With a bit of algebraic manipulation you can also obtain the equations that describe spirograph curves – see this link for the details.

So, we have a set of parametric equations and we want to plot the result. In Mathematica the ParametricPlot command is what we need so let’s give our 12 parameters some numbers and see what we can come up with.

ParametricPlot[{Sin[2 t + Pi/16] Exp[- 0.02 t] + Sin[6 t + 3 Pi/2] Exp[-0.0315 t], Sin[1.002 t + 13 Pi/16] Exp[-0.02 t] + Sin[3 t + Pi] Exp[-0.02 t]}, {t, 0, 167}, PlotRange -> All, Axes -> None]

This is all very nice but it would be much nicer if we could manipulate the parameters with a set of sliders rather than having to manually type them in each time. My first attempt at producing such a graphical user interface to the above function in Mathematica looked like this (click the image to download an interactive notebook version that can be used in the free Mathematica Player application from Wolfram)

I quite like this version as you can see all of the parameters at once but it turned out to be too big for inclusion in the Wolfram Demonstrations Project. I tried various tricks to try and shoe-horn all of those parameters into a smaller applet and was about to give up when an employee at Wolfram sent me some code that sorted out the size problem by introducing a set of tabs. I like his solution so much that I’ll probably be writing about it soon in a separate article. The resulting Wolfram Demonstration was published today – click on the image below if you’d like to take a look.

Things that I haven’t done yet but might in the future include

• Animate the plot so that it looks more like the real thing.
• Add the ability to modify the starting amplitude of each pendulum.

Of course the source code is available so if you have a burning desire to do any of these yourself then feel free – but please let me know if you do. I hope that you enjoy the results of these applets and would love to see any particularly interesting images that you might come up with – sending the equation parameters would be useful as well.
Parameters for reproducing the images above

Hover your mouse over a plot to see what image number it is

• Image 1: f1=3.001 f2=2 f3=3 f4=2 d1=0.004 d2=0.0065 d3=0.008 d4=0.019 p1=0 p2=0 p3=pi/2 p4=3pi/2
• Image 2: f1=10 f2=3 f3=1 f4=2 d1=0.039 d2=0.006 d3=0 d4=0.0045 p1=0 p2=0 p3=pi/2 p4=0
• Image 3: f1=2.01 f2=3 f3=3 f4=2 d1=0.0085 d2=0 d3=0.065 d4=0 p1=0 p2=7 pi/16 p3=0 p4=0
• Image 4: f1=2 f2=6 f3=1.002 f4=3 d1=0.02 d2=0.0315 d3=0.02 d4=0.02 p1=pi/16 p2=3pi/2 p3=13 pi/16 p4=pi

Harmonograph Resources

Hopefully, this article has whetted your appetite for harmonographs – if so then you might find the following resources interesting.

## Wolfram Demonstrations has a makeover

August 22nd, 2008

The Wolfram Demonstrations site has had something of a makeover and I think it looks great – definitely worth checking out if you have not been there for a while. If you are new here and haven’t heard about the Wolfram Demonstrations site then feel free to browse around Walking Randomly to see what I have written about it in the past. Alternatively you might care to head over there and see what it’s all about for yourself.

There are over 3500 different demonstrations available now – all of which can be downloaded and played with for free using Wolfram’s Mathematica Player. With everything from Spirographs through to Quantum Mechanics you will not fail to find something that interests you. I have got a few ideas swirling around my head at the moment so expect to see a few more from me soon (I also take requests by the way).

The only thing that really spoils the new site is the little picture of me that is currently under the ‘Featured Contributors’ section ;)

## Carnival of Maths #39

August 22nd, 2008

The 39th Carnival of Mathematics has been posted over at It’s the Thought that Counts and the wide variety of articles on offer there is as good as ever. Topics include pole vaulting, knots, the statistics of Olympic performance and the Joy of Hex along with a while lot more! I defy you to find something you are not interested in.

## How to save money if you are a train commuter in the UK.

August 22nd, 2008

I spend a good proportion of my life commuting to and from work on the train, about 10 hours a week in fact, and so it follows that I spend a lot of time at train stations. I also have a coffee habit and will spend at least 2 pounds a day on my morning latte. This can rise to 5 pounds if I am in need of comfort food such as a sausage sandwich or chocolate croissant (usually on Monday mornings). So, I spend a reasonable amount of dosh at train station cafe’s. In particular I spend most of it at Pumpkin near platform 8 of Sheffield train station.

One day, the nice lady who served me told me that I could get 20% off everything I buy at that cafe by simply signing up for a BiTE card. I am naturally suspicious of such claims and was about to politely ignore her but the guy behind me in the queue said “it’s true – I’ve got one…Look!” and proceeded to get 20% off his breakfast.

It turned out that it was my lucky day because the lady behind him said “I’ve got a spare one – you can have it if you like” and she handed it to me. It was too late for me to get a discount on that morning’s coffee but I have been getting 20% off everything there ever since and that soon adds up to a significant amount of cash.

So if you are like me and spend a lot of money at the cafe in the train station ask them if they offer a discount on presentation of a BiTE card. If they do then sign up for one here – www.bitecard.co.uk

Reminder: This applies to the UK only.

Disclaimer:As mentioned above – I didn’t need to sign up as I was handed a card by a friendly fellow commuter so I have no idea how much email / snail mail you will receive from them as a result.

## Walking Randomly’s first birthday

August 20th, 2008

Exactly one year ago today I wrote the first post on what has become my own little piece of the web. Walking Randomly was created on a whim after a conversation between myself and a web developer called Matt who was leaving the University to set up his own business. Beer was involved (for me anyway – he is tee-total) and so the details of the conversation are fuzzy to say the least but the net result was that I ended up with a version of Word Press installed on a server in the States along with the domain name of my choosing and an email that said “Have fun blogging.”

When someone goes to that amount of trouble on your behalf it would be churlish not to actually do something with it so I started writing about whatever entered my rather chaotic thoughts to see if I could make anything of it.

So, one year and 120 posts later, has it been succesful? Well, that very much depends on your point of view. My brother is an economist and he may well ask “Has it made you any money?” The answer to that question is “Not a penny!” – in fact it costs me money (although not much – I think Matt is giving me mates rates on hosting). So from this point of view it is a complete failure. In my defense, however, apart from a few Amazon Associate links, I haven’t attempted to make any money from it so my lack of monetary success is hardly surprising.

How else can one measure the success of a blog? Number of hits per day perhaps? Well, depending on which analytical tool I choose to believe, Walking Randomly gets somewhere between 250 (according to awstats) and 670 (according to webalizer) visits per day and this is rising steadily. Then there is the number of RSS subscribers which currently stands at 143 according to Feedburner. The number of RSS subscribers fluctuates on a daily basis but the general trend is upwards so I am at least going in the right direction. These figures might not be stellar but they aren’t bad considering that WR is somewhat of a niche site (putting it mildly).

What other figures can I use to measure Walking Randomly? Well, it has a google Page Rank of 4 out of 10 and an Alexa rating of 1,57222,14562 – both of which are somewhat disappointing. It also has a Technorati Authority rating of 38 which puts it in the top 276,569 blogs apparently. Whichever way you choose to look at these 3 statistics, WR is not doing so well but should I care? Do these numbers actually matter? What’s your opinion?

A less numerical but, in my opinion at least, much more important measure of blogging success comes from people’s reaction to what you write. For example, if I write an article explaining how to fix a problem with MATLAB and if even only one person finds it useful enough to say so in the comments section then it pretty much makes my day. Blog comments are a powerful thing – any one of you readers could make or break my day with a well crafted one – so be gentle!

It’s even better when someone goes to the trouble of linking to your site, providing they are doing so in a positive light of course. One person linked to me recently with along with the comment “Even the title suites me. I’ve been surfing this site most of the day. It’s amazingly cool.” and I didn’t even need to pay her! I don’t think that anything I have ever done has ever been described as ‘Amazingly cool’ before – I’d call that a success. Whoever you are – Thank you!

When all is said and done I enjoy going through the process of putting a post together and I enjoy getting feedback from readers and so, if viewed as a pleasant way of passing the time, WR has been a resounding success. My only hope is that it is as much fun to read as it is to write.

Now, where’s the Champage? I have a birthday to celebrate!

## Mathematica benchmarks on the Asus EEE

August 19th, 2008

If you are interested in gadgets then you will almost certainly have heard of the Asus EEE ultra portable (and ultra cheap) range of laptops. I have yet to get my grubby hands on one but I know one or two people who have already taken the plunge and one of them wanted to install Mathematica on his Asus EEE 900.

“No problem” said I “but would you mind running the Mathematica benchamark on it for me when you’re done”

He duly did so and the results are in. For reference, he un-installed the version of Linux that comes with the EEE and put Fedora Core 9 on it instead before installing Mathematica 6.0.0. The specs of the machine are

• 900Mhz Intel Celeron M
• 1GB RAM
• 20GB Solid State Drive

To run the Mathematica Benchmark you use the following commands

Needs[“Benchmarking`”]
BenchmarkReport[]

The overall result for the Asus EEE 900 was 0.43

To give you an idea of what this might mean – here are some other results (Higher is better)

• quad-core 3.0GHz Intel Xeon (Linux 64bit) 3.67
• 2.4 GHz Pentium 4 (windows) – 1.00
• AMD 2400XP (32bit Linux) – 0.67

The full list of timings (in seconds) for the Asus EEE were (lower is better)

• Total – 200.9 (a 2.4Ghz Pentium 4 gives a total of 100)
• Test 1 – 5.15
• Test 2 – 2.41
• Test 3 – 3.10
• Test 4 – 15.90
• Test 5 – 18.20
• Test 6 – 1.81
• Test 7- 3.33
• Test 8 – 10.30
• Test 9 – 50.00
• Test 10 – 5.06
• Test 11 – 8.44
• Test 12 – 7.35
• Test 13 – 7.38
• Test 14 – 27.20
• Test 15 – 35.30

I’m not going to explain what each of these tests actually does because this is a post for current Mathematica users who are curious about Asus’ machines rather than a post about the benchmark itself.

## The reality of the 3G iPhone – not as amazing as Apple wants us to think.

August 13th, 2008

When I first heard about the 3G version of Apple’s iPhone I started drooling. When I first saw the TV adverts and initial reports from bloggers I started wanting. Despite all this drooling and wanting, however, I have so far resisted the temptation to ditch my Windows Mobile based HTC TyTn II (or Kaiser as it’s sometimes called) in favour of Apple’s device for once simple reason – it looked too good to be true.

The more I read about the iPhone, the more I am coming to the conclusion that it isn’t anywhere near as wonderful as Apple and their followers would have us think. An example – this morning I saw a video on youtube made by someone in Boston who was comparing the performance of his 3G iPhone with the ‘Unslow’ advert recently released by Apple and the real thing was somewhat lacking to say the least. It looked much closer to what I experience every day on my 3G Windows Mobile phone.

I have been down this road before. Late last year I was lusting after my current phone, the aforementioned TyTn II, and gobbled up every tidbit of information I could find with gusto. It looked like it had everything I wanted in a mobile device and more besides – a worthy succesor to my aging Dell Axim x51v. By the time it was released by T-Mobile in the UK (renamed as the MDA Vario 3) I just couldn’t wait any longer and ordered mine on the very day of release. For a short while I was in love with it but it didn’t take long for it’s many shortcomings to show through and I often find myself wishing that I hadn’t jumped on the bandwagon so quickly. I miss my Dell :(

This isn’t the only issue I have with the iPhone of course but I’ll save those for another time. It’s an interesting product and I’ll continue watching with interest but, for now at least, I won’t be parting with my cash.

## Switching to a UK keyboard map in Ubuntu

August 12th, 2008

For some reason my keyboard started acting all American today – giving me a @ instead of ” for example. I genuinely have no idea what I had done to cause it but to fix it I did

sudo xmodmap /usr/share/xmodmap/xmodmap.uk

## An idea for Wolfram Demonstrations from TCMTB

August 11th, 2008

This is just a very quick post to highlight an idea from Maria over at the Teaching College Math Technology Blog. I agree with her, an application like spectra would be a cool way to browse the Wolfram Demonstrations Project. It would be even cooler if the user could control their posiiton in the cloud more directly though.

## If money were no object – what Maths software would you use?

August 7th, 2008

I’ve not really done this before out of fear of the possibility that no one would reply but I’m going to do it anyway and ask my readers a question or two.

If money were no object – what Maths software would you use? Why? Are there any commercial maths applications that you wouldn’t use – even if they were free?

I am not just thinking of general applications such as Mathematica, Maple, Matlab and Mathcad but also those that focus on something more specific such as SPSS, the NAG libraries, Origin or COMSOL.

Update (20th August 2008):Some people have questioned my motivation for asking this question so I guess it’s only fair that I lay all of my cards on the table. I do not work for any software company but I do work for a University that has site licenses for almost all of the applications I mentioned above. Furthermore I am the campus representative for many of these site licenses so I am responsible for getting them from the supplier to our users and I am sometimes involved in site license negotiations.

Back when I was a PhD student of physics (at a different university) I sat on the other side of the fence and was a user of Mathematica, MATLAB, the NAG libraries, Fortran, C++ and, occasionally, Mathcad. All of them have strengths and weaknesses but, of course, my point of view was limited only to what was useful to me at the time. I have strong opinions in some areas (I love Mathematica, I hate Mathcad and I respect MATALB for instance) that have been shaped by my own experiences but I like to have my opinions challenged whenever possible.

So, the reason for my question is simply professional and personal interest. The only agenda I have is to learn more and seek people’s opinions. I am not selling anything and I do not aim to promote any particular company. People who disagree with me are especially welcomed to comment.