Mathematica Asked on September 29, 2021
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]}]
Correct answer by Ulrich Neumann on September 29, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP