Re: How to plot derivative directly?
- To: mathgroup at smc.vnet.net
- Subject: [mg118113] Re: How to plot derivative directly?
- From: Heike Gramberg <heike.gramberg at gmail.com>
- Date: Tue, 12 Apr 2011 06:53:34 -0400 (EDT)
This has to do with the fact that Plot has attribute HoldAll (you can check this with Attributes[Plot]). This means that the derivative doesn't get evaluated until after w has been replaced with numerical values. To overcome this, you need to tell mathematica to evaluate the derivative before plugging in numbers. This can be done with evaluate: Plot[Evaluate[D[x^3 - 6 (x + 1)^2 + x - 7, x]], {x, -3, 8}] Heike On 11 Apr 2011, at 12:05, =8Aer=FDch Jakub wrote: > > Dear mathgroup, > > it seems to me, that response to my question shall be very simple, > but I cannot find it. :-( > > I want to plot the derivative of the function. I would like to do it > directly, something like: > > Plot[D[x^3 - 6 (x + 1)^2 + x - 7, x],{x,-3,8}] > > It returns: General::ivar: "-2.99978 is not a valid variable." > > I can understand that it is because local variable x from Plot command > interferes with the x variable from the D[]. > > Yes I can bypass the problem by: > deriv = D[x^3 - 6 (x + 1)^2 + x - 7, x] > Plot[deriv, {x, -3, 8}] > > which is fully functional, but as far as I know Mathematica, there must > be some simple solution how to do it directly inside the Plot[]. > > Thanks in advance for kick-off > > Jakub >