Re: More on functions & derivatives
- To: mathgroup at smc.vnet.net
- Subject: [mg3510] Re: [mg3470] More on functions & derivatives
- From: Allan Hayes <hay at haystack.demon.co.uk>
- Date: Mon, 18 Mar 1996 00:59:41 -0500
- Sender: owner-wri-mathgroup at wolfram.com
rich_klopp at qm.sri.com (Richard W. Klopp)
>Subject: [mg3470] More on functions & derivatives
Asks why the following difference arises
f[x_] := x^2
(*1*) 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.....
but
(*2*)Plot[f'[x],{x,-2,2}]
works OK.
*******
Richard:
Plot evaluates in its own way. To start with it has the attribute
HoldAll.
Plot[expr, {x,-2,2}] creates sampling numbers, say -2,-2.1, ...
then tries to evaluate expr with x = -2, then expr with x = -2.1,
...
In (*1*) it tries to evaluate D[f[x],x] with x = -2
The steps are D[f[x],x] -> D[f[-2],-2] - - > D[4,2] -> failure and
message.
In (*2*) it tries to evaluate Derivative[f][x] with x = -2.
The steps are
Derivative[f][x] -> 2#&[x] -> 2#&[2] -> 2 2 -> 4 etc.
You can see the patterns without needing Plot. Try
f[x_] := x^2; x = 2;
TracePrint[D[f[x],x]]
TracePrint[f'[x]]
Allan Hayes
hay at haystack.demon.co.uk
==== [MESSAGE SEPARATOR] ====