Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the derivative of the function?

How do I get the derivative of the following function?

g <- expression(x^2)
derivg <- D(g, 'x')
derivg
# 2 * x
g1 <- derivg(2)
# Error: could not find function "derivg"

I want to find the derivative at x = 2.

like image 326
slingblade8129 Avatar asked May 28 '16 20:05

slingblade8129


1 Answers

derivg is a call, not a function. To evaluate it at x = 2, you can do

eval(derivg, list(x = 2))
[1] 4
like image 150
Rich Scriven Avatar answered Oct 29 '22 08:10

Rich Scriven