3D plot with persp - error "arguments inadéquats" / "invalid arguments"

Hello,
I have this function :

tr_J = function(x,y) 
{
  tr_J = (y-x)/(x+y)-(x+y)**2 
  return(tr_J)
}

And I want to draw a 3D plot with persp :

require(grDevices)
x <- seq(0, 0.15, length= 100)
y <- x
z <- outer(x,y,tr_J)
res <- persp(x, y, z, theta = 90, phi = 10, expand = 0.5, col = "pink",
             xlab = "a", ylab = "b", zlab = "trace(J)",
             ticktype = "detailed", font.axis=1)
res
lines(trans3d(x,y,z=0, pmat=res), col = 3)

Then, I define new variables :

alpha = seq(0, 0.15, length= 100)
beta = (1 - alpha)/((alpha + 1)**3)
b = beta
a = alpha * beta

And I'd like to draw this line on my plot :

lines (trans3d(x=a, y=b, z, pmat=res), col = 3)

Problem : it prints :

Error in cbind(x, y, z, 1, deparse.level = 0L) %*% pmat : 
  arguments inadéquats

Where is the problem ?
What sould I change ?

Thank you for your help

in the problematic line,
you are passing a which is a 100 length vector, to be the x values, and b which is the same length, so far so good, as that is 100 pairs of x,y values, but for z ? you pass z , which is 10000 long.
The function doesnt know what to do.
Can you think of a way to pass an appropriate 100 length vector in for the z on that line ?

I have found a solution with writing :

lines(trans3d(x=a, y=b, z=tr_J(x,y), pmat = res), col = 2)

Thank you very much for your answer :slight_smile:

Happy if I helped. I never looked at these 3D functions before. interesting.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.