The Rosenbrock function
x <- seq(-2, 2, .1)
> y <- seq(-2, 5, .1)
> xyz <- data.frame(matrix(0, length(x)*length(y), 3))
> names(xyz) <- c('x', 'y', 'z')
> n <- 0
> for (i in 1:length(x)) {
+ for (j in 1:length(y)) {
+ n <- n + 1
+ xyz[n,] <- c(x[i], y[j], Rosenbrock(c(x[i], y[j]))[[1]])
+ }
+ }
> print(wireframe(z ~ x*y, data = xyz, scales = list(arrows = FALSE),
+ zlab = 'f(x, y)', drape = T))
x <- seq(-2, 2, .1)
> y <- seq(-2, 5, .1)
> xyz <- data.frame(matrix(0, length(x)*length(y), 3))
> names(xyz) <- c('x', 'y', 'z')
> n <- 0
> for (i in 1:length(x)) {
+ for (j in 1:length(y)) {
+ n <- n + 1
+ xyz[n,] <- c(x[i], y[j], Rosenbrock(c(x[i], y[j]))[[1]])
+ }
+ }
> print(wireframe(z ~ x*y, data = xyz, scales = list(arrows = FALSE),
+ zlab = 'f(x, y)', drape = T))
0 Comments