Fractal Intro | Mandelbrot | Sierpinski | Gallery | Return to Homepage |
---|

The Mandelbrot set is the set of all complex numbers c such that iterating z <= z^2 + c does not ascend to infinity, starting with z=0.

The terms

We could probably find a few elements in the Mandelbrot set by pencil and paper, but in order to crank out enough iterations to produce even a semi-decent graph before dying of either old age or a mental segmentation fault, we will want to determine the elements of the Mandelbrot set using a simple computer program. I will use Java-like pseudocode. Let us first declare a complex number class complexNumber:

// A class for complex numbers. class complexNumber { private double a, b; // a and b from the form a + bi public complexNumber(double realNumber, double imaginaryNumber) { // Class constructor. a = realNumber; b = imaginaryNumber; } public double realPart() { // Returns real value a. return a; } public double imaginaryPart() { // Returns imaginary value b. return b; } public double absoluteValue() { // Returns vector magnitude, sqrt(a^2 + b^2). return (sqrt(exp(a,2)) + exp(b,2))); } }

Each object in the complexNumber class has two double-precision fields,

With the one sentence description of the Mandelbrot set at the top of the page, we will write a function checkMandelbrotElement() for checking whether

checkMandelbrotElement(int N, complexNumber c) { for (int i=N, complexNumber z=0; i>=0; i--) { if (i == 0) { inTheSet(c); } else if (z.absoluteValue() > 2) { notInTheSet(z); break; } else { z = z^2 + c; } } }

The program implements the described algorithm, taking as input the number of iterations

So we have a function that checks whether any one complex number

// True monitors do not have the same width as height, but we will assume so to make computation easier. #define monitorWidth 800; #define monitorHeight 800; generateMandelbrot(complexNumber c, int N) { int pixels[i][j]; for (i=0; i<=monitorWidth; i++) { for (j=0; j<=height, j++) { // Note 4 explains subtracting (i,j) by 400 and dividing by 200 complexNumber z = new complexNumber( ((i-400)/200), ((j-400)/200) ); checkMandelbrotElement(N, z, c); } }

Thus we now have a program which checks if each pixel on a screen is a member of the Mandelbrot set dictated by the parameters

How can we get more colors? The code above only puts pixels in one of two categories, in the set, or not in the set. To get more categories, we could make a more complicated program that assigns a color to pixel

n |
z <= z^{n} + c |
z <= z-bar^{n} + c |
---|---|---|

We end our discussion of the Mandelbrot set with two pictures. The left picture (leftmost) views the entire Mandelbrot set. The right picture is actually the highly magnified image of a small fraction of the first picture. Look closely at the center of the second picture, and you can see a small black figure identical to the leftmost picture but reduced in size. Click on the file link below to witness this cyclic repetition of the set's complexities. The fantastic 12-second MPEG clip starts at topmost view of the Mandelbrot set, and zooms in, showing reductions of the same figure we started with along the way. Highly recommended.

Update: Looks like I have lost the aformentioned file. More precisely, inst.eecs.berkeley.edu erased it. But here is a much better one, produced by Thomas Marsh and Jan Hubicka of Xaos. Includes many zoom-ins. The clip cannot be fast forwarded, so just watch the whole thing patiently.

- Note 1:
*Complex Numbers*

Complex numbers are numbers expressed in the form*a + bi*, where a and b are real numbers, and i is the imaginary number, the square root of -1. In fractal geometry, we graph points against two axes, a horizontal real axis and a vertical imaginary axis; this plane is often called the complex plane (as opposed to the xy plane, where x and y are both real). Hence,*4 + 5i*can be graphed on an complex plane as corresponding to point (4,5). The absolute value of a complex number is simply*sqrt(a^2 + b^2)*, which corresponds to the hypotenuese of the triangle formed by the real and imaginary parts on the complex plane.

Return to Note 1 context

- Note 1:
*z=0 Initialization*

We start with*z*equal to zero because it is the critical point of*z^2 + c*(from introductory calculus: a point where*d/dz (z^2 + c) = 0*). If the recursive function was*z = (z-1)^2 + c*, we would start with*z = 1*(*0 = d/dz [(z-1)^2 + c] = [d/dz (z-1)^2] + 0 = 2(z-1) -> 2z = 2 -> z = 1*). In some cases there may be multiple critical values, so they should all be tested.

Mathematician Pierre Fatou (1878-1929) showed that every attracting cycle for a polynomial or rational function attracts at least one critical point. Thus, testing the critical point shows if there is any stable attractive cycle. Return to Note 2 context

- Note 3:
*Diverging Condition*

In the coding of the checkMandelbrotElement() function, we say that if*|z|*is ever greater than 2, we can be assured that the*z*sequence corresponding to parameter*c*will diverge, and*c*is thus not in the set. Proof: If*|z| > 2*, then*|z^2 + c| >= |z^2| - |c| > 2|z| - |c|*. If*|z| >= |c|*, then*2|z| - |c| > |z|*. So, if*|z| > 2*and*|z| >= c*, then*|z^2 + c| > |z|*, and thus the sequence is increasing. (It takes a little more work to prove that the sequence is unbounded and diverges.)

From this line of reasoning, it follows that the bounds of the Mandelbrot set are within*|c| <= 2*. In the first iteration,*z = 0^2 + c = c*, so if*|c| > 2*, the sequence diverges. Return to Note 3 context

- Note 4:
*Computer screen scaling*

The explanation for subtracting 200 from ( i , j ) and then dividing by 400 stems from the proof given in Note 3. Since the bounds of the Mandelbrot set are*|c| <= 2*, we want the dimensions of our graph to be*[-2,2]*(real axis) by*[-2,2]*(imaginary axis) - a larger graphing space would be a waste of space. However, the pixels on a computer monitor are indexed on a*[0,monitorWidth]*by*[0,monitorHeight]*cross product set, with (0,0) being the upper-left corner. Hence we have to do some arithmetic operations on a pixel's indices prior to making a useful complex number corresponding to that pixel. To shift the origin to the center of the screen, we subtract half of monitorWidth from i and then divide this difference by a fourth of monitorWidth, and subtract half of monitorHeight from j and then divide this difference by a fourth monitorHeight:

complexNumber z = new complexNumber( (i-(monitorWidth/2))/(monitorWidth/4) , (j-(monitorHeight/2))/(monitorHeight/4) );

So, if monitorWidth = monitorHeight = 800, then*i=0 -> (0-400)/(200) = -2*;*i=800 -> (800-400)/(200) = 2*;*j=0 -> (0-400)/(200) = -2*;*j=0 -> (800-400)/(200) = 2*. Thus we produce only complex numbers in the cross product of*[-2, 2]*and*[2, 2]*. Return to Note 4 context

Home | Introduction to Fractals | Mandelbrot | Sierpinski | Gallery |
---|

William Wu, Copyright 2000-2002 ©. All rights reserved.