我试图在R中运行以下代码(取自R维基百科页面的底部),因为我想在我启动并运行后自己玩它:
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)
我已成功下载并安装了caTools软件包。 R控制台通过消息
确认了这一点package ‘caTools’ successfully unpacked and MD5 sums checked
它会告诉我存储它的位置。
然而,它然后抱怨说:Error in write.gif(X, "Mandelbrot.gif", col = jet.colors, delay = 900) :
object 'X' not found
我看不出有任何问题 - 上面的代码中没有明确定义X?
感谢您提供的任何帮助。