xin wei
2010-Sep-24 20:41 UTC
[R] why I could not reproduce the Mandelbrot plot demonstrated on R wiki
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) 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 -- View this message in context: http://r.789695.n4.nabble.com/why-I-could-not-reproduce-the-Mandelbrot-plot-demonstrated-on-R-wiki-tp2591429p2591429.html Sent from the R help mailing list archive at Nabble.com.
Peter Dalgaard
2010-Sep-25 07:33 UTC
[R] why I could not reproduce the Mandelbrot plot demonstrated on R wiki
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.pngSave 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
belisario
2011-Jul-19 16:14 UTC
[R] why I could not reproduce the Mandelbrot plot demonstrated on R wiki
I had the same problem with the code of the Wikipedia in a 64-bit Windows 7. The gif works fine if I use the executable located in bin\x64 instead of bin, which produces the ugly gif eg, in a cmd: <the_R_path>\bin\x64\Rscript.exe example.r I realised the solution using the --verbose flag Sorry about my english -- View this message in context: http://r.789695.n4.nabble.com/why-I-could-not-reproduce-the-Mandelbrot-plot-demonstrated-on-R-wiki-tp2591429p3678522.html Sent from the R help mailing list archive at Nabble.com.