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
Another way to do it is:
f[x_]:= x^3 - 6 (x + 1)^2 + x - 7
Plot[f'[x],{x,-3,8}]
Or, perhaps a bit better f the function is much more complicated:
Plot[Evaluate[f'[x],{x,-3,8}]
--
Murray Eisenberg mur...@math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower phone 413 549-1020 (H)
University of Massachusetts 413 545-2859 (W)
710 North Pleasant Street fax 413 545-1801
Amherst, MA 01003-9305
David
Hi Jakub,
have a look at
http://reference.wolfram.com/mathematica/ref/HoldFirst.html (an
attribute being set for Plot) and use
Plot[D[f[x],x]//Evaluate,{x,x0,x1}]
Peter
Well, you can do this:
Plot[Evaluate[D[x^3 - 6 (x + 1) 2 + x - 7, x]], {x, -3, 8}]
But I think it's worth defining your function as a function.
g[x_] := x^3 - 6 (x + 1) 2 + x - 7
Plot[g'[x], {x, -3, 8}]
--
Helen Read
University of Vermont
or
Clear[f]
f[x_] = x^3 - 6 (x + 1)^2 + x - 7;
Plot[f'[x], {x, -3, 8}]
Bobby
On Mon, 11 Apr 2011 06:05:40 -0500, =A6er=FDch Jakub <Ser...@panska.cz> 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
>
>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[].
More specifically, Plot substitutes a numerical value for x
every where it appears in the expression then evaluates the
expression. The way to plot the derivative is to force
evaluation of the derivative before Plot substitutes a numerical
value for x. That is you want to do:
Plot[Evaluate[D[x^3 - 6 (x + 1)^2 + x - 7, x]], {x, -3, 8}]
And even if you could somehow get
Plot[D[x^3 - 6 (x + 1)^2 + x - 7, x],{x,-3,8}]
to work, you really wouldn't want to do that since it would mean
re-evaluating the derivative for each numerical value of x. That
would require a lot of unneeded computation.
Jakub, the Plot[] function picks a set of discrete x values (within
the range specified, very closely spaced to create the smooth graph)
and tries to evaluate your function with those numbers in place of the
x's. This creates a problem when it then tries to evaluate
D[-3^3-6(-3+1)^2+(-3)-7, -3], since you cant differentiate with
respect to a number like -3, hence the 'General::ivar: "-2.99978 is
not a valid variable." ' error message. You can get it to evaluate the
derivative before substituting in numbers for x by simply enclosing
your derivative inside an Evaluate[]
Plot[Evaluate[D[x^3 - 6 (x + 1)^2 + x - 7, x]], {x, -3, 8}]
Hope that helps!
-Stefan
--Anthony
this is due to
In[3]:= Attributes[Plot]
Out[3]= {HoldAll, Protected}
You must force Mathematica to evaluate the first parameter of Plot
before Plot goes on processing. The easiest way to accomplish this is an
explicit "Evaluate":
Plot[Evaluate[D[x^3 - 6 (x + 1) 2 + x - 7, x]], {x, -3, 8}]
Hope this helps,
ciao,
WW.
On 04/11/2011 01:05 PM, Šerých Jakub wrote:
> Plot[D[x3 - 6 (x + 1)2 + x - 7, x],{x,-3,8}]
might this:
Plot[D[x^3 - 6 (x + 1)^2 + x - 7, x] // Evaluate, {x, -3, 8}]
be what you are looking for?
Have fun, Alexei
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
--
Alexei Boulbitch, Dr. habil.
Senior Scientist
Material Development
IEE S.A.
ZAE Weiergewan
11, rue Edmond Reuter
L-5326 CONTERN
Luxembourg
Tel: +352 2454 2566
Fax: +352 2454 3566
Mobile: +49 (0) 151 52 40 66 44
e-mail: alexei.b...@iee.lu
--
This e-mail may contain trade secrets or privileged, undisclosed or
otherwise confidential information. If you are not the intended
recipient and have received this e-mail in error, you are hereby
notified that any review, copying or distribution of it is strictly
prohibited. Please inform us immediately and destroy the original
transmittal from your system. Thank you for your co-operation.
Plot[f'[x], {x, -3, 8}]
Attributes[Plot]
{HoldAll, Protected}
Plot[Evaluate[D[f[x], x]], {x, -3, 8}]
Bob Hanlon
---- "=C5 er=C3=BDch Jakub" <Ser...@panska.cz> wrote:
==========================
> Plot[D[x^3 - 6 (x + 1)^2 + x - 7, x],{x,-3,8}]
Use Evaluate:
Plot[D[x^3 - 6 (x + 1)^2 + x - 7, x] // Evaluate, {x, -3, 8}]
--
_________________________________________________________________
Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de
In[9]:= deriv=D[x^3-6 (x+1)^2+x-7,x];
plot1 = Plot[deriv,{x,-3,8}]
An alternative method with Evaluate inserted:
In[11]:= plot2 = Plot[Evaluate[D[x^3-6 (x+1)^2+x-7,x]],{x,-3,8}]
The two plots are the same.
In[12]:= plot1==plot2
Out[12]= True
Richard Hofler
________________________________________
From: =8Aer=FDch Jakub [Ser...@panska.cz]
Sent: Monday, April 11, 2011 7:05 AM
Subject: How to plot derivative directly?
Dear mathgroup,
Plot[Evaluate[D[x^3 - 6 (x + 1)^2 + x - 7, x]], {x, -3, 8}]
Heike