I made this derivative script and I wanted to plot the graph of the result of the derivative along with the function. But I am not able to make the graph in the multivariate case f(x,y), the result of the derivative is taken as a value and not as a function. See the example below:
DD7<-function(x,r,contador=1){
dy<- substitute(x)
if(contador<1) {
stop("Grau de derivada menor que 1")
}
if(contador==1) {
der<-D(dy,c(r))
print(der)
x<- y <- seq(-3,3,length=50)
z<- outer(x,y,der)
persp(x,y,z)
}
else {
der2<- DD(D(dy,r),r,contador-1)
print(der2)
x2<- y2 <- seq(-3,3,length=50)
z2<- outer(x,y,der2)
persp(x,y,z2)
}
}
DD7(x*y^2,"y",1)
Error in get(as.character(FUN), mode = "function", envir = envir) :
object 'der' of mode 'function' was not found

DD7and callDD8. Not reproducible: we don't have yourxoryvalues.base::outerneeds to be a function, whereasderis a call. I don't know why you needouterthere, if you calleval(der)in place of that, you get a vector the length ofxandy(which, in this example, is the value fromy^2, the derivative I think you're targeting). What makes you believe you need toouterthex/yvectors? That'll produce a vectorlength(x)*length(y)long, fyi.