[R] why I could not reproduce the Mandelbrot plot demonstrated on R wiki

xin wei xinwei at stat.psu.edu
Sun Sep 26 04:50:39 CEST 2010


hi, peter:
thank you for your attention. adding the line you suggested did display the
static Mandelbrot plot with good resolution on R graphics device. However,
the resulting gif file still come out ugly. the R wiki page I was referring
to is the following:
http://en.wikipedia.org/wiki/R_(programming_language)
where the nice Mandelbrot plot and sample codes are provided.....

i would appreciate your help if you can provide further hint. 

thanks





Peter Dalgaard-2 wrote:
> 
> On 09/24/2010 10:41 PM, xin wei wrote:
>> 
>> I am trying to reproduce the nice looking of Mandelbrot demonstrated by R
>> wiki page by the following code:
>> 
>> 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)
> 
> Hmm, I couldn't be bothered with the caTools, but it looks fine for me
> with
> 
> image(X[,,20],col=jet.colors(100))
> 
> Perhaps you need jet.colors(n) as well?
> 
> 
> 
>> however, the gif file created by this looks much worse than what is shown
>> on
>> R wiki page, see the comparison as follows (left one is what i created)
>> 
>> http://r.789695.n4.nabble.com/file/n2591429/Picture1.png 
> 
> Save for the odd color scheme, the one on the left looks like a
> Mandelbrot set, the one on the right appears to be iteration 4. I
> couldn't find your original source for this on wiki.r-project.org?
> 
> 
> -- 
> Peter Dalgaard
> Center for Statistics, Copenhagen Business School
> Phone: (+45)38153501
> Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: http://r.789695.n4.nabble.com/why-I-could-not-reproduce-the-Mandelbrot-plot-demonstrated-on-R-wiki-tp2591429p2714024.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list