Basic Mandelbrot set in R

On a train home from Norwich at the end of a very long day...

The Mandelbrot set has been back in the news of late due to the
unveiling of the awesome "Mandelbulb" 3-D fractal:

http://www.skytopia.com/project/fractal/mandelbulb.html

So my programming exercise for tonight was to write a complete program
to compute and plot a basic old-style 2-D Mandelbrot set:

http://en.wikipedia.org/wiki/Mandelbrot_set

in fewer than 10 lines of code. It turns out to be quite doable in R,
exploiting the fact that R has built-in support for complex numbers
and can perform vectorised operations on complex matrices. Code and
image attached. I should point out that this vectorised approach has
limitations, but leads to code that executes reasonably quickly in
vectorised languages like R (and python, and Matlab,...). It's
certainly not how I'd approach the problem using a language that
doesn't have a huge penalty associated with explicit looping over
pixels (like C, or Java, or ...). See the above wikipedia article for further details,
including pseudocode that is a lot longer than 10 lines! ;-)

Mandel

Click here to download:
mandel.R (0 Bytes)