# Is there a better syntax to obtain the derivative of a function as a function/operator? (e.g. for simple plotting of derivtives of functions, etc.)

When trying to plot a derivative of a function, (I take Sin as a simple example), the naive approach

Plot[D[Sin[x], x], {x, 0, 2 π}]


fails. One can work around this by a replacement rule

Plot[D[Sin[y], y] /. y -> x, {x, 0, 2 π}]


which then indeed plots the derivative, i.e. the Cos.

This is an example of the general syntax "problem", that if I have a function f, say of one variable, and I want to obtain f' as well as a function, then I have to perform this cumbersome definition of f' with that replacement rule:

fprim[x_]:=D[f[y], y]/.y → x


I know that this works, and in this sense that is not an actual problem. However I always thought this a bit cumbersome that one has to introduce an additional dummy variable, and from a mathematical perspective I would rather have the derivative to be a function by default, to which arguments can be applied.

So the question is: Is there a better syntax to obtain f' as a function than the one I used in the examples above?

Try Derivative
Plot[ Derivative[1][Sin ][x], {x, 0, 2 \[Pi]}]

or Evaluate
Plot[Evaluate[D[Sin[x], x]], {x, 0, 2 \[Pi]}]

• Or Plot[Sin'[x], {x, 0, 2 Pi}]` Jul 29, 2020 at 5:55