Skip to content

Instantly share code, notes, and snippets.

@yuugit
Created June 17, 2013 23:29
Show Gist options
  • Save yuugit/5801438 to your computer and use it in GitHub Desktop.
Save yuugit/5801438 to your computer and use it in GitHub Desktop.
Mandelbrot
initial.mandel <- function(input) {
x <- seq(input$xmin, input$xmax, length.out=input$xresol)
y <- seq(input$ymin, input$ymax, length.out=input$yresol)
outer(x, y, function(x, y) complex(real=x, imaginary=y))
}
calc.mandel <- function(c) {
z <- list(c) # z_1 = c の計算(?)
for (i in 1:input$niter) {
z[[i+1]] <- z[[i]]^2 + c # z_{i+1} = z_i^2 + c の計算
}
return(z)
}
input <- list(xmin = -2, xmax = 1, xresol=60, ymin = -1, ymax = 1, yresol=30, niter = 10)
input <- list(xmin = -2, xmax = 1, xresol=300, ymin = -1, ymax = 1, yresol=100, niter = 20)
c <- initial.mandel(input)
z <- calc.mandel(c)
z.last <- z[[input$niter+1]]
plot(c[which(abs(z.last) > 10)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment