The common man’s guide to the Mandelbrot Set.

Z → Z2 + C

I think I first saw the Mandelbrot set in 2nd grade, in the Guinness book of world records. It was listed as “Most complicated mathematical object ? “. While reasonably interesting, at 2nd grade I was more intrigued by the obese motorcycling twins , and that picture of the giant spider. A number of years later, I picked up “Chaos” by James Gleick which explained things more thoroughly. At that point in high school I was already handy in programming simple games and graphics in BASIC. Plotting the Mandelbrot set intrigued me, but I was discouraged as it had those troubling imaginary numbers. My graphing calculator didn’t natively support such things, and my knowledge of BASIC wasn’t that extensive. So, the dream sat deferred.

This last year, spurred on partly by trying to get Euler’s e^i Pi x through my head, i revisited the land of imaginary numbers. Taking things nice and slowly, it wasn’t so bad. Adding (a + bi) and (c + di) was just ((a+c) + (b+d)i ). And multiplication of those same two terms was ac + (ad)i + (bc)i + (bd)i2. Mandelbrot came to mind, and I decided to look up the equation.

The core equation is expressed as Z → Z2 + C. The arrow part indicates this equation is iterative. One starts with 0 as the initial value for Z, and any complex number for C. For example, say we choose to run this equation with (1 + 1i) as our first C value:

1st iteration: 02 + (1 + 1i) = (1 + 1i)

2nd: (1 + 1i)2 + (1 + 1i) = (2i) + (1 + 1i) = (1 + 3i)

3rd: (1 + 3i)2 + (1 + 1i) = (-8 + 6i) + (1 + 1i) = (-7 + 7i)

4th: (-7+7i)2 + (1 + 1i) = … and so on

So, ok. I’m doing stuff with imaginary numbers, and I’m using the word “iterate” which is kind of neat. But how does this result in my cool picture of the Mandelbrot set?

The set is painted on the “imaginary plane”. The imaginary plane is a 2d space, with an X axis and a Y axis. Any point on this plane represents a distinct imaginary number, (a + bi). The X coordinate represents the real part, and the Y coordinate represents the imaginary part. So, to find the point that represents (3 + 2i), go over 3 on the X axis, and up 2. That’s the point.

Any point on this plane is either “in” or “not in” the Mandelbrot set. If the point is “in” it shows up on the graph and gets colored in. To find out, pick a point on the plane, and use it as your initial C value in the main equation (Use zero for the initial Z value). Then run through your iterations and monitor the “size” of the result each time. Here “size” is defined as the complex number’s distance from the origin, via Pythagoras, the “size” of (a+bi) is √(a2 + b2). One of three things will happen. 1) the value will get larger and larger, shooting off toward infinity. 2) The value will get smaller and smaller until it bounces around, always less than about 1. Or 3) The value will work it’s way back to a previous Z value, and be in an infinite loop.

For cases 2) and 3), the initial C value is said to be in the set. Go ahead and color it in. You’re now plotting the Mandelbrot set. I’ll give away the surprise, and reveal that the famous shape lies within about (-2 < x < 1) and (-1.2 < y < 1.2).

Colorful renderings come from plotting points that are technically “out” of the set, and rising towards infinity. As it turns out, once the equation returns a value with a size greater than 2, it can be regarded as lost. Keep track of how many iterations before it gets to 2, and color accordingly. One color for 5 iterations, another color for 10 iterations, and so on.

I whipped up a program to handle this for me. Here are two renderings of my results:

At about five minutes of computation per shot, not the fastest, but pretty decent I think. (A big improvement over essentially the same code running on a ti-82 graphing calculator which took about 6 hours to render.) Slow rendering aside, I got a cool feeling watching the set slowly revealed, and understanding how it worked.

√