关于persp
:
x <- seq(.0001, 10000, by = (10000 - .0001) / 1000)
y <- seq(.01, .5, by = (.5 - .01) / 100)
fun <- function(x, y) {
x + y ^ 2 - 2 * y
}
persp(x = x, y = y, z = fun(x, y))
它返回
Error in persp.default(x = x, y = y, z = fun(x, y)) :
invalid 'z' argument
In addition: Warning messages:
1: In x + y^2 :
longer object length is not a multiple of shorter object length
2: In x + y^2 - 2 * y :
longer object length is not a multiple of shorter object length
我该如何解决这个问题?
谢谢,
答案 0 :(得分:4)
你快到了。只需使用outer
使用'fun'获取矩阵:
persp(x = x, y = y, z = outer(x, y, fun))