I derive the following mathematical expression.
exp1<-expression(100/x)
D(exp1,"x")
# Lo que me resulta.
-(100/x^2)
What I want is that this result can be fed into a function. In order to obtain the numbers that will be generated with that result.
I have tried the following:
f1<-function(x){
D(exp1,"x")
}
But trying to execute the function returns the same result.
# Evaluando en el valor de 4.
f1(4)
# Arroja.
-(100/x^2)
This happens because the result of the derivative is of class call
.
My question is how could I put the result of the derivative into a function and be able to evaluate it. That is, in my example, when executing the result is -6.25 ( -100/16
)
f1(4)
-6.25
# Que el resultado de esta operación sea -6.25
I'm not exactly sure why it works, but my first instinct was to put an
eval()
explicit and it worked. I think that's what you were looking for.