Apr 26, 2010

Discovering Fractals: The Lorenz Attractor

It's been a long time since I posted anything about fractals. I've been looking at them a bit more recently and have decided to put up more pretty pictures for you all. Today we're looking at the Lorenz Attractor, which is one of the earliest discovered chaotic systems - technically many systems had been discovered before that, but this is one of the ones that was discovered after someone (that someone being Lorenz) had figured out what chaos was.

It's a fairly simple system, although less simple than the previous ones I've written about. It follows a set of differential equations(I just grabbed these from the Wikipedia page):
dx/dt = σ * (y - x)
dy/dt = x * (ρ - z) - y
dz/dt = x * y - β * z
If we translate these to C (I do all my fractal stuff in C, since it seems to be hopelessly slow in anything else) we get:
for (t = 0; t < NUM_ITERATIONS; t++){
x1 = x + dt * sigma * (y - z);
y1 = y + dt * (x * (rho - z) - y);
z1 = z + dt * (x * y - beta * z);

x = x1;
y = y1;
z = z1;

// plot point
You'll want some initial conditions, I used x = 0.1, y = 0.0, z = 0.0. You also have a time-step dt, which I set to 0.001. This determines how "smooth" your picture will look.

Here's a picture of what it looks like:This is with NUM_ITERATIONS = 100 000. I just used a mostly orthographic projection - the x just maps to x, and y maps to y when you plot it on the screen, and you ignore z. I did a bit of scaling and translating to the x and y so that it fit nicely into an 800x800 window.

The interesting thing is the colours (it may look ugly, but there is some science behind it!). This picture is effectively a trace of a particle moving through time. The more red it is in this picture, the earlier it is in the particle's path, and the more blue, the later (obviously purple ones are in the middle). It's interesting because except for the little red swirls at the beginning there, the red, purple and blue paths are all fairly mixed up (it might look like the blue ones are more clustered, but keep in mind that blue pixels are plotted later, and therefore will overwrite any pixels that might have been there before). This is evidence of something called topological mixing, which as I understand from my brief digging through Wikipedia basically means that the paths taken at different time ranges will inevitably overlap.

Anyway, that's enough about the actual math behind chaos theory. You can probably even take on Jeff Goldblum now! I'll work on other fractals sometime and give you guys more neat pictures.


Anonymous said...

The fractal egg:


The fractal swirl:


Anonymous said...

what makes this fractal?

Rob Britton said...

It has a fractal dimension of roughly 2.06. There is some debate as to whether or not this makes something "a fractal," but since this is not an academic paper I'm accepting the word as a decent approximation ;)

Christel said...
This comment has been removed by a blog administrator.