I'm trying to run the following code in R (taken from the bottom of the R Wikipedia page) as I'd like to play around with it myself once I get it up and running:
library("caTools")
jet.colors <- colorRampPalette(c("#00007F", "blue", "#007FFF", "cyan", "#7FFF7F",
"yellow", "#FF7F00", "red", "#7F0000"))
dx <- 400 # define width
dy <- 400 # define height
C <- complex( real=rep(seq(-2.2, 1.0, length.out=dx), each=dy ),
imag=rep(seq(-1.2, 1.2, length.out=dy), dx ) )
C <- matrix(C,dy,dx) # reshape as square matrix of complex numbers
Z <- 0 # initialize Z to zero
X <- array(0, c(dy,dx,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=900)
I have succesfully downloaded and installed the caTools package. The R console confirms this with the message
package ‘caTools’ successfully unpacked and MD5 sums checked
and it tells me the location where it is stored.
However, it then complains that:
Error in write.gif(X, "Mandelbrot.gif", col = jet.colors, delay = 900) :
object 'X' not found
I cannot see any problem with this - isn't X clearly defined in the above code?
Thanks for any help you can offer.