# How to define a derivative of a function at some point?

Consider a function

derivative[x_]:=D[Sin[x],x]


When calling it with some argument, like derivative[2], instead of $$\cos(x)$$ it gives me $$\partial_{2}\sin(2)$$. Is it possible to define a function in one string that first takes the derivative and then returns it at the given point? And to generalize this to an arbitrary function f, i.e.

derivative[f_,x_]:=D[f,x]

• Derivative[1][f][x], here f is a pure function. I think you want a function such as derivative[f_,x_,x0_] ? Oct 28 '20 at 23:24
• @cvgmt : yes, you are correct. Oct 29 '20 at 7:55

I think simplest and cleanest way would be to use

derivative[f_] := f'


E.g. if you evaluate

derivative[Sin]


you get the pure function

Cos[#1] &


and therefore

derivative[Sin][x0]


returns

Cos[x0]

• Oh this is much more elegant than my solution! Does this generalise to arbitrary derivatives, e.g. derivative[f_] := f^(1,0) for f[x_,y_] = Cos[x]Sin[y] for example? Nov 1 '20 at 12:42
• For that case you might want to take a look at Derivative. You could say derivative[f_] := Derivative[1,0][ f ]; Beware that in that case you need too invoke derivative[ Cos[#1] Sin[#2]& ], (or g[x_,y_] := Cos[x]Sin[y]; derivative[g] ) because your function takes 2 arguments and mathematica needs to know which one is the first argument and which one the second.
– Gert
Nov 1 '20 at 21:23

I think the issue here is one of the order of operations. Consider instead:

derivative[x_] := ( D[Sin[y],y] /. y -> x )


And, more generally,

derivative[f_, x_] := ( D[f[y], y] /. y -> x)