Wednesday, April 18, 2007

Mandelbrot Set with R Animation

A few days ago I had the opportunity of having dinner with Benoît Mandelbrot
when he gave a seminar talk at the Bu Mathematics and Statistics Department. At the same time I was trying to find a way to produce animation in R. I came across this great post which was relevant for both purposes.

Using the code



### Reproduced from http://tolstoy.newcastle.edu.au/R/help/05/10/13198.html
### Written by Jarek Tuszynski, PhD.

library(fields) # for tim.colors
library(caTools) # for write.gif
m = 400 # grid size
C = complex( real=rep(seq(-1.8,0.6, length.out=m), each=m ),
imag=rep(seq(-1.2,1.2, length.out=m), m ) )
C = matrix(C,m,m)


Z = 0
X = array(0, c(m,m,20))
for (k in 1:20) {
Z = Z^2+C
X[,,k] = exp(-abs(Z))
}
image(X[,,k], col=tim.colors(256)) # show final image in
write.gif(X, "Mandelbrot.gif", col=tim.colors(256), delay=100)


we get the following animation

3 comments:

adam said...

Looks great. Could you explain the algorithm , what it does in the M-set interior ?
Adam
fraktal.republika.pl

makeyourownmandelbrot said...

A blog about the Mandelbrot set accompanying an ebook designed for school-level readers - it'll take you from basic arithmetic, through the idea of iteration, give a very gentle introduction to complex numbers, and hold your hand through coding your own Mandelbrot and Julia sets.

http://makeyourownmandelbrot.blogspot.co.uk/

Comments welcome on both the blog and the ebook (published soon) - the aim is to maximise understanding and I believe anyone with school maths can do it.

Sorry to post here but I hope people will find it through your excellent post about the Mset.

makeyourownmandelbrot said...

The easy to understand guide to making your own Mandelebrot (using Python) is out:

http://www.amazon.co.uk/dp/B00JFIEC2A/
https://play.google.com/store/books/details?id=OVBTAwAAQBAJ

As ever, feedbac via google+ or
http://makeyourownmandelbrot.blogspot.co.uk/ is welcome!