Re: Issuing Function Calls within a Plot command

*To*: mathgroup at smc.vnet.net*Subject*: [mg111538] Re: Issuing Function Calls within a Plot command*From*: Peter Breitfeld <phbrf at t-online.de>*Date*: Wed, 4 Aug 2010 07:33:23 -0400 (EDT)*References*: <i38rbb$cuq$1@smc.vnet.net>

Plot[f[x],{x,0,5}] has the Attribute HoldAll. This means here, that to generate the plot Mathematica first chooses numbers for x e.g. x=0, x=0.5,... and calculates f[0], f[0.5],... In your case it tries to calculate the D[0^2,0] which is nonsense, so you get warnings and not plot drawn. To force the calculation of the derivative you should use Evaluate: Plot[D[myFunction[x],x]//Evaluate,{x,0,5}] which will work. It is stated in the documentation of Plot "More Information". Andrew DeYoung wrote: > Hi, > > It seems like Mathematica has difficulty plotting calls to other > functions. Is this true? For example, can you help me understand why > the following does not plot? > > If I write > > myFunction[x_] := x^2; > Plot[D[myFunction[x], x], {x, 0, 5}] > > nothing plots. > > If I write > > myFunction[x_] := x^2; > Plot[D[myFunction[x][x], x], {x, 0, 5}] > > again, nothing plots. > > However, if I compute the derivative of the function outside of the > Plot command, > > myFunction[x_] := x^2; > myDerivative = D[myFunction[x], x] > Plot[myDerivative, {x, 0, 5}] > > the derivative of x^2 (i.e., 2x) plots correctly. > > Can anyone please help me understand why my first two tries do not > work, but my third try does? > > Many thanks in advance. > > Andrew DeYoung > Carnegie Mellon University > adeyoung at andrew.cmu.edu > -- _________________________________________________________________ Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de