More on functions & derivatives
- To: mathgroup at smc.vnet.net
- Subject: [mg3470] More on functions & derivatives
- From: rich_klopp at qm.sri.com (Richard W. Klopp)
- Date: Sat, 16 Mar 1996 22:37:01 -0500
- Organization: SRI International
- Sender: owner-wri-mathgroup at wolfram.com
The following must be related to the recent thread [mg3384] substitution
of functions in derivatives. Can someone help me understand what is going
on?
I define a function:
f[x_] := x^2
I try to plot its first derivative, but get errors instead.
Plot[D[f[x],x],{x,-2,2}]
General::ivar: -2. is not a valid variable.
General::ivar: -2. is not a valid variable.
Plot::plnr:
CompiledFunction[{x}, <<1>>, -C<<9>>de-][x]
is not a machine-size real number at x = -2.....
I try to plot its first derivative another way, and it works as expected.
Plot[f'[x],{x,-2,2}]
Out[21]=
-Graphics-
Digging deeper, I look at the derivative form that I began with, the one
that refused to plot.
D[f[x],x] // FullForm
Out[22]//FullForm=
Times[2, x]
Let's compare with the other derivative form, the one that plotted successfully.
f'[x] // FullForm
Out[23]//FullForm=
Times[2, x]
Dang, it looks exactly the same! Can someone explain? Is there some kind
of evaluation sequence problem that isn't apparent? I can't pick the
answer out of the book section 3.5.1 ff.
Thanks,
Rich_Klopp at qm.sri.com
Appendix
---------
Following are some other permutations that didn't reveal the answer. I'm
very interested in knowing why the form that I began with abover does not
work.
The following fails.
In[25]:=
Plot[D[f[x],x] /. x -> x, {x,-2,2}]
General::ivar: -2. is not a valid variable.
General::ivar: -2. is not a valid variable.
Further output of General::ivar
will be suppressed during this calculation.
...
Out[25]=
-Graphics-
The following works.
In[26]:=
Plot[f'[x] /. x -> x, {x,-2,2}]
Out[26]=
-Graphics-
Also works.
In[27]:=
Plot[Derivative[1][f][x], {x,-2,2}]
Out[27]=
-Graphics-
More output showing that D[] and f' seem to be exactly the same yet don't
act the same.
In[28]:=
D[g[x],x] // FullForm
Out[28]//FullForm=
Derivative[1][g][x]
In[29]:=
g'[x] // FullForm
Out[29]//FullForm=
Derivative[1][g][x]
--
Rich Klopp
rich_klopp at qm.sri.com
==== [MESSAGE SEPARATOR] ====