MathGroup Archive 2010

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

Search the Archive

Re: Issuing Function Calls within a Plot command

  • To: mathgroup at smc.vnet.net
  • Subject: [mg111528] Re: Issuing Function Calls within a Plot command
  • From: David Reiss <dbreiss at gmail.com>
  • Date: Wed, 4 Aug 2010 05:49:51 -0400 (EDT)
  • References: <i38rbb$cuq$1@smc.vnet.net>

Because you are differenciating with respect to a number.

The value of x in the argument of the plot function is substituted
first and then the argument is evaluated, effectively resulting in
attempting to differentiate your function evaluated at numerical
values  with respect to those numerical values.

Try the alternative


Plot[D[myFunction[z], z] /. z -> x, {x, 0, 5}]

or

Plot[Evaluate[D[myFunction[x], x] ], {x, 0, 5}]

to force the differentiation to take place first (since Plot has the
HoldAll attribute).


which will work.  However you may want to think through why you are
including the unevaluated differentiation within the Plot command
anyway: it will take place at each plot point and thus be quite
inefficient...

Hope this helps,

David

On Aug 3, 6:34 am, Andrew DeYoung <adeyo... at andrew.cmu.edu> 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
> adeyo... at andrew.cmu.edu



  • Prev by Date: Re: Mathematica- Use a previous equation into the function Function
  • Next by Date: Re: Issuing Function Calls within a Plot command
  • Previous by thread: Re: Issuing Function Calls within a Plot command
  • Next by thread: Re: Issuing Function Calls within a Plot command