Mathworks Sent Me a Rubik’s Cube

So I’m sitting in my office, bashing away at my keyboard, when a small parcel arrives on my desk. I wasn’t expecting anything, I’m new here so it wouldn’t be work-related, it wasn’t just a letter but a small parcel containing an object quite clearly in the third dimension. Who on Earth would be sending me 3D objects in the post to my work!?

I looked at the address label to verify it was definitely for me. It was.

Then I noticed the Mathworks logo stamped in the corner. I have no dealings with Mathworks, other than using their software Matlab while I was a student. Most people who know me know I’m a huge fan of Matlab. But I don’t think they know that. Surely they have no reason to write to me, never mind send me 3D objects in the post.

I opened up the parcel to find a Mathworks-branded Rubik’s Cube. I’d seen one of these before – the week before on Twitter @MATLAB posted a picture of one of these:

And so I looked inside the parcel to see if there was anything else. There was a letter:

Mathworks has seen your Tweet, so we hope you enjoy the Rubix Cube

Brilliant! (Apart from the misspelling of Rubik’s Cube…)

I then tweeted:

I think it’s great. It’s an interesting puzzle (another addition to my collection of cubes) as each side contains a different picture made up of the 3×3 grid on each side, rather than just matching colours. Also I noticed that once I solved it the first time, the centre pieces were the wrong way round. This is something I’ve never considered before because on a normal cube, you just have to get the pieces on the right side. You would know if a corner or edge piece was wrong because then the colours wouldn’t be the same on each side, but the centres – I always assumed they didn’t rotate relative to the corner and edge pieces! But I’d never noticed because there’s no orientation to the centres on normal cubes.

I had a play and couldn’t figure out a fool-proof method of solving the centres, so I put it down, carried on coding (in PHP, not Matlab) and left it for me to figure out on the train. I managed to do it on the train back to work the next morning, but then messed it up again trying to explain to Mike how I’d done it! I played with it some more that weekend, and became a bit more aware of how the middle-centres moved when you did the final step using my solving method (switching the 4 centres on the top layer around), and can usually solve it using a technique I developed, but it’s far from perfect and seems a bit of a hacky solution. Maybe with more inspection I’ll figure out a general solution for the centres.

Anyway – huge thanks to Mathworks for the prezzie – I love it! Also I appreciate the human touch applied here.

I think I deserve it, anyway – the amount of PR I’ve done for them by telling everyone how awesome Matlab is for the last 3 years or so!

Limerick 2011

[This is an extended version of an article I wrote for MSOR Connections magazine – which you can read online]

During the final year of my combined honours degree in Mathematics and Computing at Manchester Metropolitan University (MMU) I received an invitation to a two-day Student Mathematical Modelling Workshop at the University of Limerick in the Republic of Ireland, hosted by the Mathematics Application Consortium for Science and Industry (MACSI). The workshop was followed by the 82nd European Study Group with Industry. The maths course at MMU is highly oriented around real world problem solving involving mathematical modelling, dynamical systems, numerical methods, ODEs & PDEs and contains a strong programming element, so this was something I thought would be good to attend.

My friend Chris and I applied for our places on the workshop and booked our flights. What better way to unwind after completing a maths degree than being put to the test! While packing our shared suitcase for the trip, we weighed the case and realised we were too heavy, so we repacked – some of it crammed in to our backpacks, some we left behind. Arriving at the luggage check-in desk, the suitcase was weighed and we were well under the limit. At this point we realised we had looked at the wrong units on the weighing scales. Typical mathematical modelling error – how apt. We reshuffled the contents of our cram-packed flight bags and put things back in to the suitcase, thinking idiots of ourselves.

Not really knowing how useful we’d be in helping solve problems, nor which type of problems we would like to tackle, we began by sizing up the problems set online while on the plane. I chose a problem on Equity Options & CDS Risk Management because it seemed an interesting situation to work with. The group consisted of both those who had studied financial mathematics and those who hadn’t, so there was a mix of abilities and understanding. The finance people got on with what they have done with similar problems, explaining themselves along the way, and others found useful things to bring to the group. I personally looked at the data we had been given, analysed the trends in the evolution of option prices over time and ran a Monte Carlo simulation in MATLAB to demonstrate the effectiveness of the strategy.

The second week was the study group so the lecture theatre was filled out with academics as well as the students who had stayed on. I chose to work on a problem in Electricity Prices and Demand Side Management, looking at estimating usage for a company called Crystal Energy in Ireland who offer electricity to companies at variable tariffs based on consumption. I worked with other members of my group on analysing the company’s data in MATLAB and Mathematica. We were able to produce useful information for the group, including isolating volatile periods in the day (e.g. between 12-2am) and in the year (e.g. mid-late December) by looking at the absolute difference (error) between corresponding timeslots and plotting contour maps. A report explaining our findings has been submitted for publication. As the study group fell after our final exams, it gave us a great insight in to the usefulness of what we had learned at university, indicated gaps in our knowledge and inspired us to attempt to solve problems that arise, small and simple or bigger and more complex problems alike. It gave us both the courage to realise that this is something we could do with our lives, applying our skills in such a real and meaningful way which could lead to significant results in personal, small or large scale industry problems.

A couple of times during the trip, I arranged Skype calls with Peter Rowlett, where he interviewed by about the study group and conference for his Math/Maths podcast, along with his American co-host Samuel Hansen. You can listen to these here: Episode 53, Episode 55

We had a fantastic time staying on the beautiful campus of the University of Limerick. We enjoyed the food, drink and surroundings, but most of all, the company – everyone there was really interesting, and it was great to share conversation with such an intelligent group of like-minded mathematicians. Although the daytime was spent working on maths problems, the trip was very social – we would move from a classroom or lecture theatre straight to the pub with the other students and staff and carry on discussions from the problems of the day, and our approaches to solving them. Also, during the second week, I received the results of our degrees – and I’d passed with second class honours.

We also took the weekend at the end of the trip to travel to Dublin, where we stayed with the family of one of the conference delegates we met. Dublin is a fantastic city, and we really enjoyed the weekend. We visited the campus of University College Dublin and its Maths Society‘s room. I was shocked to see their Maths Society was so well established that it had its own designated area of the Maths Department building! Last year I founded the Maths Society at MMU and we had nothing at all. We hung out in the Maths Society room for a while, looked at some books from their library and played on their N64! We also took a walk through the Maths Department’s own library, deep down in the basement of the building – where we walked through about five big rooms full of books – and when we reached the end, I picked up a magazine I saw on top of a box, turned it over to look at the back page, and spotted a review of a book written by my lecturer Stephen LynchDynamical Systems with Applications using MATLAB. Quite a coincidence!

Unfortunately I had some sad news on the night we left – a friend called to say one of my friends from the university canoe club, Dave Evans, had died in a climbing accident on Mont Blanc. This was devastating, and I found the news very difficult to take in. A hard thing to deal with – losing a friend so young. Dave was just 24 and had been out of university less than a year. RIP.

MATLAB and Java Assignments

I’ve had a hectic week this week trying to get all my assignments in. I had a MATLAB assignment due in on Thursday and a Java one due in today.

The MATLAB one involved two questions: the first was a banking system which calculated interest and mortgage payments; the second was an animation of a sporting event. The first question involved a switch statement to begin, so the user was prompted to choose one of four options, each one taking them to a certain part of the code and allowing them to perform their chosen banking task. Within each of those I had to use nested for loops and if statements, taking input values and getting the loops to work out how to calculate the answer based on their inputs (for instance if the user entered 10 years, the loop would have to run 10 times), which was kind of fiddly but fairly easy. If you don’t know what a for loop is, it’s quite common in many programming languages, and here’s a brief explanation:

This means that the loop runs 10 times (for i=1, for i=2, …, for i=10) and does the code in between each time. So the first time it runs, the variable i=1, so when i is multiplied by 2, a = 2 (in MATLAB this would return the answer each time). The second time, i=2 so a=4, then each time i increments by 2 until i=10 and a=20. This is a very basic example but there are many applications this can be used for.

For the animation, I had to draw the figures using x- and y-coordinates of polygons, filling them in with a chosen colour, and then use a for loop to change their coordinates (i.e. move all the x-coordinates one space to the left every time the loop runs). It started off as a simple yacht animation, but I got carried away when I added the second yacht and made it into a pirate chase with a bullet being fired.

It actually sailed smoother before I added the movement up-and-down, but the code to make it do this was rather complex and imaginative so I left it in to get more marks. I nested an if statement within the for loop:

So every time the loop ran (the ellipsis doesn’t show the bits of code that get the x-coordinates to move the the left), the if statement checks to see whether j is divisible by 2: if it is, the y-coordinates increment by 1; if not, they decrement. This makes the boat (and all its related shapes, again not shown) move up and down alternately. The assignment handout included a video of an animation worth 90% and it was much simpler than mine so I should have scored fairly well.

Once I had this finished and submitted I had to get on with my Java assignment: to make a simple sketching program in Java, as an applet for HTML. About 24 hours before the deadline I hadn’t done much, only the very basics, and then spent most of the afternoon helping 3 other people to get that far, went to have a beak for about an hour and a half and went to train, then did a little more before going out to see the Inbetweeners at a club in Manchester, then woke at 10:00 the next morning to carry on with it, just 2 hours before the de this was only enough to get 40%. I worked on it every second for the next two hours, trying bits of code to get it to do more advanced functions, I added colours, a reset button, a change background colour function, different shapes, a text field, another text field, a change size field, and so on, until I had completed the list of functions to include, which were given with percentages of how much you would get if you did them, up to 70% (a First Class), and it said extra marks would be awarded for extra features and for the general ‘look and feel’ of the applet, so I should have done pretty well. I submitted at 11:59. Just in time.

Java and MATLAB seem to be very similar in what you can do and the code you use to do it, but MATLAB’s syntax is much simpler. Next year’s Java will be much more complex, with a much stronger emphasis on objects. As for MATLAB, I specifically chose the units which included MATLAB programming, one of which was about computer graphics and virtual environments, and most people who aren’t interested in programming will have gone elsewhere so it should get much more hardcore.