R outer function Error in persp.default(x, y, z) : invalid 'z' limits

断了今生、忘了曾经 提交于 2019-12-11 10:55:30

问题


could someone explain to me why these two pieces of codes return two diferent things? the first one :

x<-y<-seq(from=-1,to=1,by=0.1)
one<-function(x,y){
    x
}
z<-outer(x,y,FUN=one)
persp(x,y,z)

returns the surface it should.

while :

x<-y<-seq(from=-1,to=1,by=0.1)
one<-function(x,y){
    array(1, dim=length(x))
 }
 z<-outer(x,y,FUN=one)
 persp(x,y,z) 

returns : "Error in persp.default(x, y, z = outer(x, y, one)) : invalid 'z' limits"


回答1:


For the second case, plotting the plane z=1, you just need to specify the desired zlim yourself, e.g.

persp(x,y,z,zlim=c(0,2))

The persp function expects to plot in a 3-dimensional space. The default is to try to plot over the ranges of x, y and z, but in this case z's range is degenerate.



来源:https://stackoverflow.com/questions/32054123/r-outer-function-error-in-persp-defaultx-y-z-invalid-z-limits

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!