Re: Issuing Function Calls within a Plot command

• To: mathgroup at smc.vnet.net
• Subject: [mg111521] Re: Issuing Function Calls within a Plot command
• From: Curtis Osterhoudt <cfo at lanl.gov>
• Date: Wed, 4 Aug 2010 05:48:35 -0400 (EDT)

```myFunction[x_] := x^2;
Plot[Evaluate[ D[myFunction[x], x] ], {x, 0, 5}]

The function "Plot" has the attribute "HoldAll", which means that it holds the argument unevaluated for as long as possible. I think it does this to keep things in an analytic state, and allows things such as symbolic manipulation (as your differentiation operator, "D", uses). In this case (as in many plotting cases), the use of Evaluation makes sure that things resolve to numbers when they should.

At least in earlier versions of Mathematica, it was emphasized that one should Evaluate arguments to Plot whenever possible; in the latest documentation, I don't see that emphasis.

On Tuesday, August 03, 2010 04:34:19 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.
>
> work, but my third try does?
>
>
> Andrew DeYoung
> Carnegie Mellon University
>
>

--
==================================
Curtis Osterhoudt
cfo at remove_this.lanl.and_this.gov
==================================

```

• Prev by Date: Re: Issuing Function Calls within a Plot command
• Next by Date: Re: Scoping constructs Block, Module, ModuleBlock
• Previous by thread: Re: Issuing Function Calls within a Plot command
• Next by thread: Re: Issuing Function Calls within a Plot command