Wednesday, October 27, 2010

Mandelbrot Set

The lab assignment for CS this week was to create a function which determines if various complex numbers are in the Mandelbrot Set.  To determine if the number is in the set, begin with the complex number z = 0 +0i.  Then, follow the sequence such that z(sub x+1) = z(sub x) + c.  In this case, c is the complex number which you are attempting to identify in the set.  If the sequence diverges (meaning that it continues towards infinity), then the complex number c is not in the set.  Then, the program I wrote plotted all of the points which are in the set, creating a fractal like this:

The black points are in the Mandelbrot Set.
This image in and of itself is pretty, just because it is a fractal and has a interesting shape which has been computed mathematically.  There is a special trick to determine if a Mandelbrot set diverges: if the magnitude of the complex number z every exceeds 2, the complex number c is not in the set.  For convergence, there is no definitive formula, which means that the absolute accuracy of the image (the plotting of the points) depends on how many iterations (the number of times you step through the sequence).

Since there is this definitive sequence, it is possible for the points not in the set to diverge at different rates depending on the value of c.  Because of this difference, it is also possible to look at the rate of divergence and plot diverging points in different colors to signify how quickly they diverge.  I spent about two hours playing with this part of it, since there are so many things you can do with the different colors.  Consider the following examples:

The varying degree of red signifies the rate of divergence.
In this example, the colors are assigned not in a gradient, but in a rainbow.
In this example, it is easier to see the gradient of various velocities.
An interesting part of the Mandelbrot Set (and other fractals) is the ability to zoom into the image and to be able to see a high degree of detail even at some of the smallest stages.

Zoomed into the medium circle in the image above.
Fractals are beautiful and so much fun to play with.  I would really love to look into some other fractal equations and implement them myself in order to create other interesting and attractive images, if only for fun.  If you would like your own personal fractal for a background or whatever, let me know what color you would like and I can said you one.

The remainder of this CS assignment consist of the option to program a couple games: Nim and Mastermind, which I am really looking forward to since it should be fun to play with these as well.

No comments:

Post a Comment