我有一个3D功能 - 让我们说De Jong功能:
fdejong <- function (x, y) {
return (x^2 + y^2)
}
我如何在3D中绘制它的情节?我想从维基百科中获得类似的效果:
答案 0 :(得分:6)
试试这个:
fdejong <- function (x, y) {
return (x^2 + y^2)
}
x <- seq(-10, 10, length= 30)
y <- x
z <- outer(x, y, fdejong)
z[is.na(z)] <- 1
op <- par(bg = "white")
persp(x, y, z, theta = 30, phi = 30, expand = 0.5, col = "lightblue")
答案 1 :(得分:4)
您也可以使用莱迪思wireframe
功能。 (使用@ user1020027的数据)
fdejong <- function (x, y) {
return (x^2 + y^2)
}
x <- seq(-10, 10, length= 30)
y <- x
z <- outer(x, y, fdejong)
z[is.na(z)] <- 1
require(lattice)
wireframe(z, drape=T, col.regions=rainbow(100))