Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Plotting the Mandelbrot set

  1. Nov 25, 2008 #1
    I found this image on wikipedia: http://en.wikipedia.org/wiki/Image:Mandel_zoom_00_mandelbrot_set.jpg

    and i have seen this image like many times, but i have never understood as to how it is plotted. How is the value of the color decided? Plus, if it is a complex plane, how are the axes defined? I remember reading that if a point lies in the complex set which is being plotted, it is given the color white, otherwise it is plotted as black [or vice versa, not sure]. Either ways, how are the other color values decided?
  2. jcsd
  3. Nov 25, 2008 #2
    I made a little java program that generates pictures like that one so I could make them for my desktop. The source code is bundled with it. Here is the link:

    http://dl.getdropbox.com/u/120094/Chaos%20Program%20and%20Source.jar [Broken]
    Last edited by a moderator: May 3, 2017
  4. Nov 25, 2008 #3


    User Avatar
    Science Advisor

    You interpret each point on the plane (your monitor screen) as a point (x,y) in the complex plane: x+ iy. The Mandelbrot set is defined as the set of points (x,y) such that the sequence z0= 0, zm+1= z2+ x+ iy. You run that iteration long enough to see if it converges or not (if |zn|> 2, it diverges). Color the point (x,y) black if it converges, white if not. Most "Mandelbrot" set pictures look at how many iterations it take to make |zn|> 2 and color according to that. Those points are NOT in the Mandelbrot set but close to it and it makes a prettier picture!
  5. Nov 25, 2008 #4
    the longer it takes for a point to diverge the brighter it's colored
  6. Dec 3, 2008 #5
    A Mandelbrot set program needs just a few essential pieces. The main engine is a loop of instructions that takes its starting complex number and applies the arithmetical rule to it. For the Mandelbrot set, the rule is this: zz2+ c, where z begins at zero and c is the complex number corresponding to the point being tested. So, take 0, multiply it by itself, and add the starting number; take the result—the starting number—multiply it by itself, and add the starting number; take the new result, multiply it by itself, and add the starting number. Arithmetic with complex numbers is straightforward. A complex number is written with two parts: for example, 2 + 3i (the address for the point at 2 east and 3 north on the complex plane). To add a pair of complex numbers, you just add the real parts to get a new real part and the imaginary parts to get a new imaginary part:

    2 + 4i
    + 9 – 2i
    11 + 2i

    To multiply two complex numbers, you multiply each part of one number by each part of the other and add the four results together. Because i multiplied by itself equals –1, by the original definition of imaginary numbers, one term of the result collapses into another.

    2 + 3i
     2 + 3i
    6i + 9i2
    4 + 6i
    4 + 12i + 9i2
    = 4 + 12i – 9
    = – 5 + 12i

    To break out of this loop, the program needs to watch the running total. If the total heads off to infinity, moving farther and farther from the center of the plane, the original point does not belong to the set, and if the running total becomes greater than 2 or smaller than –2 in either its real or imaginary part, it is surely heading off to infinity—the program can move on. But if the program repeats the calculation many times without becoming greater than 2, then the point is part of the set. How many times depends on the amount of magnification. For the scales accessible to a personal computer, 100 or 200 is often plenty, and 1000 is safe.

    The program must repeat this process for each of thousands of points on a grid, with a scale that can be adjusted for greater magnification. And the program must display its result. Points in the set can be coloured black, other points white. Or for a more vividly appealing picture, the white points can be replaced by coloured gradations. If the iteration breaks off after ten repetitions, for example, a program might plot a red dot; for twenty repetitions an orange dot; for forty repetitions a yellow dot, and so on. The choice of colours and cutoff points can be adjusted to suit the programmer’s taste. The colours reveal the contours of the terrain just outside the set proper.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook