Home » Analytics » A Missing Mandelbrot Who Dun It

A Missing Mandelbrot Who Dun It

R in the Cloud

R for Quantitative Finance

Software

Train in R

Despite the GIF format's limitations, it can b...

Image via Wikipedia

I had tried recreating this .gif using #catools in a windows environment, but the resolution was not quite good. it seems package catools is dependent on Operating System,

Anyway, there are two approaches to creating this code- one is given at

http://blog.revolutionanalytics.com/2010/09/mandelbrot-set.html

and is simply

library(caTools)  # external package providing write.gif function
jet.colors = colorRampPalette(c("#00007F", "blue", "#007FFF", "cyan", "#7FFF7F",
        "yellow", "#FF7F00", "red", "#7F0000"))
m = 600     # define 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)  # reshape as square matrix of complex numbers
Z = 0     # initialize Z to zero
X = array(0, c(m,m,20)) # initialize output 3D array
for (k in 1:20) {  # loop with 20 iterations
 Z = Z^2+C    # the central difference equation
 X[,,k] = exp(-abs(Z)) # capture results
}
write.gif(X, "Mandelbrot.gif", col=jet.colors, delay=100)

The other approach is from http://rtricks.blogspot.com/
and also suggests who the original author of this fascinating
 Mandelbrot gif was
- apparently it was created in 2005 and is 
5 years old

### 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)
and finally- this time I used Linux /Ubuntu 10
and got the colors correct- just happy to find who created the original image
---------------------------------------
Of course 2010 had its share of notable deaths- 
Benoit Mandelbrot passed away this year



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Predictive Analytics- The Book

Conferences

Books

Follow

Get every new post delivered to your Inbox.

Join 745 other followers