Kings College Cambridge
Sightseeing
The Royal Albert Hall
Imperial College graduation ceremonies are held here
The Lorenz Attractor
A simple demonstration of chaos with 3 equations.
The Natural History Museum London
Nautilus shape: The Fibonacci Sequence and the Golden ratio
The Golden ratio is known as ϕ = ½(1+ √5) appears to be embedded in nature!
The River Thames
London Skyline
London Skyline
The Natural History Museum
Charles Darwin monument

Scripts and source code


Here are some scripts and code that I have written in Julia, Python, C++, GNU Octave, Perl, Python and Java.  The scripts vary in topics and include: geometry, chaos and strange attractors, chess, set theory and approximating \(\pi\) to high accuracy very quickly; feel free to download and experiment! All the compilation and running instructions can be found in the GitHub "Readme.txt" files that appear after clicking the download icons.

 

GitHub    Julia notebook     Counting equilateral triangles within a trapezium using symmetric sequences

This code is related to a problem I once had to solve as part of a high school project, which ended up being a lot more tricker than expected (especially since I was the only one in the whole school working on it!). This is the second of two notebooks.

 

GitHub    Python Jupter notebook     Counting equilateral triangles within a trapezium

This is the first of two notebooks (see above). The article related to this notebook used an asymmetric summation technique.

 

GitHub    C++    N-Queens  on an N x N chesssboard

Based on the classic problem of placing 8 Queens on a chessboard without any of them being in check; this code works out the positions of N-Queens on an N-by-N board, and then prints the result in a HTML & text file.

 

    Java    Lorenz Attractor

A nice little GUI window that shows the Lorenz attractor (a solution to a coupled set of non-linear time dependent variables).  The solutions can be depicted as spiralling trajectories in 3D space and they curves demonstrate how tiny changes in the trajectories lead to very dramatic changes in the time evolution of the curves.   All computers will run Java without a problem and you probably have it installed already (remember the philosophy of Java is "write it once run it anywhere"). This code was written around 2005 so it is pretty old, but its still quite charming.

If you don't want the hassle of downloading and running the executable you can still view a snapshot of  the butterfly effect by clicking here

 

    GNU Octave or Matlab    Lorenz Attractor

A very easy  to use script that plots the 3D Lorenz attractor when the command 'lorenz' is typed at the GNU Octave command prompt.

 

    C++    Calculate the subsets of size \(k\) from a larger set of size \(n\)

If \(|A|= n\) then all sets \(B\) are calculated where  \( B \subset A\) and  \(|B|= k\). Two codes are written: one which is simple to read and uses a recursive method and another code is iterative and will probably do much better at scaling \(n\) to large values.
Fun fact: I wrote the iterative code during a 3-4 hour job interview for a company called Arithmetica in Coventry, although the interviewer agreed that the iterative method seemed to work, he couldn't see why! Generally speaking iterative methods are usually faster and safer to use, my instincts are always to avoid recursion because it can result in a program getting stuck in an endless cycle of a function calling itself (potentially) or slowing down to a complete crawl.

 

   Perl    Music playlist splitter

A Perl script that splits a music .pls files into artist and song titles text files. This was written to illustrate the usefulness of regular expression pattern matching, which is a very useful tool for working with filenames and the text within files.

 

    C++    Approximating \(\pi\) - MAPM library.

 

A Machin-type formula is used to calculate PI. 

$$\frac{\pi}{4} = 44\arctan(\frac{1}{57})+7\arctan(\frac{1}{239})-12\arctan(\frac{1}{682})+24\arctan(\frac{1}{12943})$$

I have used the MAPM library in my Phd research to see if  accumulating round off error could be the cause, of the numerical instability found in one of the methods used to calculate fluid motion. The code for the latter is also available for download at the above link with instructions to help compile the code.