As the title says, what's the cleanest way to plot a function's derivative in Mathematica? The two best methods I could find were either to define the function beforehand and then use prime notation, e.g.
F[x_]=x^2;
Plot[{F[x], F'[x]}, {x, -10, 10}]
Or to write the function in terms of a different variable and plot it like so:
Plot[{x^2, D[t^2, t] /. t -> x}, {x, -10, 10}]
Both of these methods appear clunky when used in more complex expressions, so I was wondering if there was a simple way to write it, akin to
Plot[{x^2, IgnoreXFromOutsideScope[D[x^2, x]]}, {x, -10, 10}]
Plot[{x^2, Evaluate@D[x^2, x]}, {x, -10, 10}]? – Syed Nov 03 '22 at 02:25Plot[{F[x], F'[x]}, {x, -10, 10}]why do you call it clunky? when used in more complex expressions could you show an example of such more complex expression where the above causes problems? Btw, in Mathematica, there are at least 10 different ways to do the same thing. So pick one way that feels easy for you to understand and use. – Nasser Nov 03 '22 at 02:29Plot @@ {{x^2, D[x^2, x]}, {x, -10, 10}}– userrandrand Nov 03 '22 at 02:37Fis, you have to make the change in one place, not in 2 places. But it is up to you. – Nasser Nov 03 '22 at 02:43Plot @@ {{({#, D[#, x] } &)[x^2]}, {x, -10, 10}}– userrandrand Nov 03 '22 at 02:43Plot[D[x^2,x],{x,0,1}]" see this answer essentially it is becausePlotdoes not evaluateD[x^2,x]right away. Instead it will keep the expression held, replace x with a number in the interval you are plotting like 0.3 and then try to evaluateD[0.3^2,0.3]. All solutions given in the above link are ways to circumvent that issue. – userrandrand Nov 03 '22 at 03:08