Back to lesson 1 |
Introduction |
What is the Mandelbrot Set?
The Mandelbrot Set is one of the most beautiful objects in mathematics. It is a fractal shape resulting from a fairly simple computation. Its real beauty, however, is that, although it is self-similar under magnification, the magnified copies are not identical to the whole. The set, in fact, contains an infinite number of different variations on itself.
The mathematical foundation
The mathematics behind the Mandelbrot Set is pretty straightforward. Consider the complex plane, the set of all complex numbers graphed along two axes. For every coordinate (x, y) on the plane, there is a corresponding complex number z = x + iy, where i = sqrt(-1).
Now, consider the series defined by
z_{0} = 0
z_{n} = z_{n-1}^{2}+C,where C is a complex number parameter. It turns out that this series may have one of two behaviors as n->infinity, depending on the value of C. For some values of C, the series may "blow up" to infinity. i.e.
lim_{n->infinity}(|z_{n}|) = infinity.In this case, we say the series escapes. For other values, the series may chaotically bounce around within a finite region of the plane. In this case, we say the series achieves an orbit.
The Mandelbrot Set is defined as the set of complex numbers such that the series z_{n} achieves an orbit. If you graph this set on the complex plane, it will form the picture we recognize as the Mandelbrot Set fractal.
Making pretty Mandelbrot Set pictures |
Performing the computation
To actually view the Mandelbrot Set, we typically need a computer to test each C and determine whether its corresponding series z_{n} escapes or achieves an orbit. Unfortunately, a computer can't directly test whether the limit of a series is infinity. However, we can make a good guess, based on the following theorem.
Theorem:Given any C, and the series z_{0} = 0, z_{n} = z_{n-1}^{2}+C,
If |z_{a}| > 2 for some finite integer a, then the series escapes.I won't go through a proof of this theorem here, but intuitively, you can imagine that once |z_{a}| passes 2, the operation of squaring it will dominate and cause the norm to blow up.
Therefore, given a C, we can test it by computing some large number of elements in the sequence, and seeing if the norm ever exceeds 2. If it does, we know that the point C = x + iy is outside the set. If it does not, we cannot say for certain, but we can guess that there is a good chance that it is within the set.
For example, here is a C++ function that tests an input for Mandelbrot Set membership:
bool in_mandelbrot_set(std::complex<double> c) { const int MAX_ITERS = 1000; std::complex<double> z = 0.0; for (int i=0; i<MAX_ITERS; ++i) { z = z*z+c; if (z.real()*z.real()+z.imag()*z.imag() > 4.0) return false; } return true; }To compute an image, we need only to iterate over the pixels, determine what complex number each pixel corresponds to, and call in_mandelbrot_set(). In general, the higher the magnification you are using, the higher value of MAX_ITERS you will probably need to generate an accurate image. I've found that a value of 1000 tends to be good enough for most low magnifications.
Colors for the image
To make a visually attractive picture based on the Mandelbrot Set, we need to assign colors to each pixel. Traditionally, pixels that are found to be in the set are colored black, and pixels found to be outside the set are colored a different color. One way of making interesting patterns just outside the set is to assign different colors based on how many iterations it took for |z_{n}| to exceed 2.
A simple coloring scheme often works very well. For example, you can interpolate smoothly between two colors to get a "fade" effect, or you can alternate between two colors and get a stripe pattern. The choice of a coloring scheme is part of the art of making Mandelbrot images.
Back to lesson 1 |
The GLOW Toolkit