       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=
-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//FullForm=
Times[2, x]

Let's compare with the other derivative form, the one that plotted successfully.

f'[x] // FullForm

Out//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:=
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=
-Graphics-

The following works.
In:=
Plot[f'[x] /. x -> x, {x,-2,2}]

Out=
-Graphics-

Also works.
In:=
Plot[Derivative[f][x], {x,-2,2}]

Out=
-Graphics-

More output showing that D[] and f' seem to be exactly the same yet don't
act the same.
In:=
D[g[x],x] // FullForm
Out//FullForm=
Derivative[g][x]
In:=
g'[x] // FullForm
Out//FullForm=
Derivative[g][x]

--
Rich Klopp
rich_klopp at qm.sri.com

==== [MESSAGE SEPARATOR] ====

```

• Prev by Date: Re: Re-evaluation of Conditional expressions
• Next by Date: Round[1.5] != Round[3/2] = 2 ???
• Previous by thread: RunThrough[] command
• Next by thread: Re: More on functions & derivatives