MathGroup Archive 2006

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

Search the Archive

Re: Plot derivative

  • To: mathgroup at
  • Subject: [mg64951] Re: Plot derivative
  • From: "Steven M. Christensen" <steve at>
  • Date: Wed, 8 Mar 2006 01:01:01 -0500 (EST)
  • Sender: owner-wri-mathgroup at

There were a great many duplicate answers to this question.  I
have combined them all in this post.


>From: Marco Gabiccini <m.gabiccini at>
To: mathgroup at


Plot[Evaluate[Dt[Sin[x], x]], {x, 0, 1}]


>From: Arkadiusz Majka <majka at>
To: mathgroup at

You must evaluate derivative first.



>From: bghiggins at
To: mathgroup at

Wrap the argument with Evaluate:

Plot[Evaluate[Dt[Sin[x], x]], {x, 0, 1}]



>From: Bob Hanlon <hanlonr at>
To: mathgroup at

Plot has attribute HoldAll



Use Evaluate



Bob Hanlon

>From: "Borut Levart" <BoLe79 at>
To: mathgroup at

Try evaluating the argument to Plot first:

Plot[Evaluate[Dt[Sin[x], x]], {x, 0, 1}]

>From: dh <dh at>
To: mathgroup at

Hi Walter,
look at the attributes of Plot:
and you will see that it has "HoldAll". This means that Dt[Sin[x], x] 
will not be evaluated before x is replaced by a numerical value, e.g. 
Dt[Sin[0.5], 0.5]. That is not what you want. You must force evaluation by:
Plot[Evaluate[ D[Sin[x], x] ], {x, 0, 1}]

By the way, you do not need the total differential here Dt, D will do 
the job.


>From: "David Park" <djmp at>
To: mathgroup at

When making plots, I often think it is good practice to prepare the plotting
function first, so you know exactly what it is, and then put it in the Plot

f[x_] = Dt[Sin[x], x]

Plot[f[x], {x, 0, 1}];

What actually happened is explained by the fact that Plot has the attribute
HoldAll. In plotting each point, it holds the function, substitutes the x
variable and then evaluates the function. In this case the expression is
invalid when a number is substituted for x (at each place it occurs). Here
is an example when x = 0.01.

Hold[Dt[Sin[x], x]]
% /. x -> 0.01
% // ReleaseHold

Hold[Dt[Sin[x], x]]
Hold[Dt[Sin[0.01], 0.01]]
General::ivar: 0.01` is not a valid variable.
Dt[0.00999983, 0.01]

which is not what you wanted at all.

Of course, the simple answer is just to Evaluate the function in the Plot

Plot[Dt[Sin[x], x] // Evaluate, {x, 0, 1}];

But I have seen a number of postings on MathGroup where there is quite
extensive data processing put into the Plot statement. Much better, I think,
to prepare the plotting function first and disentangle derivations and data
processing from plotting.

David Park
djmp at

>From: walter hausser [mailto:nodi at]
To: mathgroup at


Why doesn't this work?


How do I do it correctly?

>From: jmt <jmt at>
To: mathgroup at

Try this : 

Plot[Evaluate[Dt[Sin[x], x]], {x, 0, 1}]

>From: Pratik Desai <pdesai1 at>
To: mathgroup at

Plot has Attribute HoldAll,  its evaluation is "non-standard"

In the mathematica book Section 2.6.5 (you can access this using the 
Mathematica tab in your help browser and type 2.6.5) you can see what 
this actually means..

The upshot is essentially use Evaluate with your plot commands and it 
works fine


Hope this helps

Pratik Desai

>From: Peter Pein <petsie at>
To: mathgroup at

Hi Walter,

Plot[Evaluate@Dt[Sin[x], x], {x, 0, 1}]

and have a look at

--> HoldAll

"HoldAll" in the documentation.


>From: Bill Rowe <readnewsciv at>
To: mathgroup at

It doesn't work because of the way Plot evaluates its arguments. That is Plot evaluates the function to be plotted by substituting a numerical value for x and expects a numerical value in return. Since you cannot take the derivative of a function with respect to a numeric argument you get an error message stating the numeric value isn't a valid variable which in turn causes Plot to complain the result of the evaluation wasn't a machine-sized real.

The solution is to force evaluation of the derivative before Plot tries to substitute numeric values. That can be done with


>From: ggroup at
To: mathgroup at

You need to wrap the argument in Evaluate[].  In other words:


  • Prev by Date: Re: General--Making the DisplayFormula style in ArticleModern look like Traditional
  • Next by Date: Re: ndsolve & compile
  • Previous by thread: Plot derivative
  • Next by thread: Re: Plot derivative