MathGroup Archive 1996

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: More on functions & derivatives:Correction

  • To: mathgroup at smc.vnet.net
  • Subject: [mg3532] Re: [mg3510] Re: [mg3470] More on functions & derivatives:Correction
  • From: Allan Hayes <hay at haystack.demon.co.uk>
  • Date: Thu, 21 Mar 1996 01:08:18 -0500
  • Sender: owner-wri-mathgroup at wolfram.com

In my previous message (copied below)

Derivative[f] should be  Derivative[1][f]

Allan Hayes
hay at haystack.demon.co.uk


********
Begin forwarded message:

> From: Allan Hayes <hay at haystack.demon.co.uk>
> To: mathgroup at smc.vnet.net
> Subject: [mg3510] Re: [mg3470] More on functions & derivatives

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] ====


  • Prev by Date: Re: solving differential equations
  • Next by Date: Table[] Why such a hog?
  • Previous by thread: Re: ListContourPlot: AxesLabels? (Q)
  • Next by thread: Table[] Why such a hog?