One of the classical example of chaos is always the Lorenz attractor. No matter how carefully you choose the values, however close they are, the end result is always different. And the fact that this never intersecting, unique set of values are bound within a domain which looks like a butterfly links it uniquely to the famous quote,
It has said that something as small as the flutter of a butterfly’s wing can ultimately cause a typhoon halfway around the world.
There is this small article in American Scientist which shines some lights on it. More than that, the following video from Veritasium goes in depth, which actually got me into plotting it out.
I wanted to implement the Lorenz attractor, which is found in the front page of Julia Plots, but using the GLMakie package which I am trying to learn.


I’ve followed the same struct setup of the Julia plots site but I’m implementing it using RK4 instead of Forward Euler followed by that site. I’ll follow the similar setup I had followed for RK4 implementation in GNU Octave / Matlab but the code is considerably smaller given this is implemented in Julia (and recording of all data is not necessary).


Consider a simplified model for the fluid circulation in a fluid layer that is heated from below and cooled from above. This is given by the following set of three coupled ordinary differential equations
This is defined within the step function below. Actually, here we will plot three Lorenz attractors, each with slightly different initial condition than the other. Let’s see how they grow!


GLMakie uses a function called Node()
to give numbers special power. That is, all these nodes, when updated, will update the functions which uses them (my current understanding; please correct if I’m wrong!). Hence, what I’ve done is to implement each point as a Node so that we step through the attractor, we can update these points and hence the plot gets updated. This update is passed to the record function along with the figure and it records the animation at a configured frame rate. Also, I’ve made the variable az
a node so that I can update azimuth (rotation) of camera for each frame. If further clarification is needed, one can refer to this youtube tutorial or GLMakie docs.


This is the end result.
Note how the three curves, initially together, diverge and continue to follow different paths!