Wednesday, 7 May 2014

The Mandelbrot Recipe

Sometimes you just want the recipe for making a Mandelbrot fractal, presented in easy to understand steps, with a diagram illustrating how it all works. Here it is... click on the image to get a fuller view.



1. Pick a rectangle on the complex plane.
If you select the rectangle with bottom left corner at (-2.25 -1.5i) and top right corner at (0.75 + 1.5i) you’ll get a good view of the Mandelbrot set. If you chose a rectangle that’s far away from the centre of the Mandelbrot, or is completely within the set, then you won’t see anything interesting.

2. Each point in this rectangle is a complex number representing c, the parameter of our iterated function.
You should pick a reasonable number of points, evenly spaced out. Too many and you’ll have lots of unnecessary calculations to do without adding much detail. Too few points and you’ll have gaps in your plot and insufficient detail.

3. For each of these points, c, iterate the function z2 +c many times.

The complex number z starts at zero, or more properly (0 + 0i). Keep a note of the completed iterations.

4. Stop iterating when either (i) you’ve reached the maximum number of iterations you’ve set yourself, or (ii) the magnitude of the function output grows more than four.
If the magnitude grows greater than 4, the point has diverged and you don’t need to keep calculating further iterations as they’ll diverge further, and may even grow so big as to cause an error in your calculator or computer.
If you’ve reached the maximum iterations, the point c very likely doesn’t diverge.

5. Colour the point c using the number of iterations reached to indicate either (i) the rate of divergence, or (ii) non-divergence for points within the set.
Remember that we have an upper limit on the number of iterations. If it is reached then the iterations did not diverge and so the point is likely to be within the Mandelbrot set. If the iterations are prematurely stopped because the magnitude of z has broken the limit we set of 4, then the orbit does diverge, and the iteration count we did reach indicates how slow or fast the divergence happens. A small iteration count means a rapid divergence.
You could chose other colouring schemes if you wanted to experiment.