onchange
功能实现
x1<-as.matrix(seq(-32.768,32.768,length=100))
x2<-as.matrix(seq(-32.768,32.768,length=100))
X<-cbind(x1,x2)
y <- outer(X,X,Ackley)
我认为这样的错误 - dim(robj)错误&lt; - c(dX,dY): dims [product 40000]与对象的长度[100]
不匹配答案 0 :(得分:1)
ackley <- function(x1, x2) {
a <- 20
b <- 0.2
c <- (2*pi)
d <- 2
fofx1 <- -a*exp(-b*sqrt(1/d*sum(c(x1,x2)^2))) -
exp(sum( cos(c*c(x1,x2))/d))+a+exp(1)
#fofx2 <- -a*exp(-b*sqrt(sum(c(x1,x2)^2)/100))-
# exp(sum( cos(c*c(x1,x2))/100))+a+exp(1)
return(fofx1)
}
Ackley <- Vectorize(ackley)
x1 <- seq(-32.768,32.768,length=500)
x2 <- seq(-32.768,32.768,length=500)
z <- outer(x1, x2, FUN="Ackley")
library(plotly)
plot_ly(x=~x1, y=~x2, z = ~z, type="surface") %>%
layout(scene=list(aspectratio = list(x = 1, y = 1, z = 1)))