Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #1604 > unrolled thread
| Started by | Šerých Jakub <Serych@panska.cz> |
|---|---|
| First post | 2011-04-11 11:05 +0000 |
| Last post | 2011-04-12 09:58 +0000 |
| Articles | 6 — 6 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
How to plot derivative directly? Šerých Jakub <Serych@panska.cz> - 2011-04-11 11:05 +0000
Re: How to plot derivative directly? Peter Pein <petsie@dordos.net> - 2011-04-12 09:53 +0000
Re: How to plot derivative directly? Helen Read <readhpr@gmail.com> - 2011-04-12 09:54 +0000
Re: How to plot derivative directly? Stefan <wutchamacallit27@gmail.com> - 2011-04-12 09:56 +0000
Re: How to plot derivative directly? Wolfgang Windsteiger <Wolfgang.Windsteiger@risc.jku.at> - 2011-04-12 09:57 +0000
Re: How to plot derivative directly? Peter Breitfeld <phbrf@t-online.de> - 2011-04-12 09:58 +0000
| From | Šerých Jakub <Serych@panska.cz> |
|---|---|
| Date | 2011-04-11 11:05 +0000 |
| Subject | How to plot derivative directly? |
| Message-ID | <inuna0$2au$1@smc.vnet.net> |
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
[toc] | [next] | [standalone]
| From | Peter Pein <petsie@dordos.net> |
|---|---|
| Date | 2011-04-12 09:53 +0000 |
| Message-ID | <io17f0$i4q$1@smc.vnet.net> |
| In reply to | #1604 |
Am 11.04.2011 13:05, schrieb Śerých Jakub:
> 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
>
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
[toc] | [prev] | [next] | [standalone]
| From | Helen Read <readhpr@gmail.com> |
|---|---|
| Date | 2011-04-12 09:54 +0000 |
| Message-ID | <io17h1$i6c$1@smc.vnet.net> |
| In reply to | #1604 |
On 4/11/2011 7:05 AM, =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
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
[toc] | [prev] | [next] | [standalone]
| From | Stefan <wutchamacallit27@gmail.com> |
|---|---|
| Date | 2011-04-12 09:56 +0000 |
| Message-ID | <io17k3$i90$1@smc.vnet.net> |
| In reply to | #1604 |
On Apr 11, 7:05 am, =A9er=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
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
[toc] | [prev] | [next] | [standalone]
| From | Wolfgang Windsteiger <Wolfgang.Windsteiger@risc.jku.at> |
|---|---|
| Date | 2011-04-12 09:57 +0000 |
| Message-ID | <io17lp$iab$1@smc.vnet.net> |
| In reply to | #1604 |
Dear Jakub,
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}]
[toc] | [prev] | [next] | [standalone]
| From | Peter Breitfeld <phbrf@t-online.de> |
|---|---|
| Date | 2011-04-12 09:58 +0000 |
| Message-ID | <io17ne$ibo$1@smc.vnet.net> |
| In reply to | #1604 |
Šerých Jakub 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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web