MathGroup Archive 2008

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

Search the Archive

Re: Anomaly? or at least a surprise.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg90271] Re: Anomaly? or at least a surprise.
  • From: Szabolcs Horvát <szhorvat at gmail.com>
  • Date: Fri, 4 Jul 2008 03:56:52 -0400 (EDT)
  • References: <g4i942$3cr$1@smc.vnet.net>

Steve Gray wrote:
> Doing D[ArcTan[x], x] gives 1/(x^2+1) as expected.
> Doing Plot[D[ArcTan[x]],{x,-10,10},PlotRange->Full] with no variable
> to differentiate by gives a correct plot (!) This is surprising - Help
> says nothing about leaving out the independent variable even when the
> function is of only one variable. 

Note that D[ArcTan[x]] does not evaluate to 1/(x^2+1), but to ArcTan[x]. 
  This is consistent with D[f,x,x] being the double derivative, 
D[f,x,x,x] the triple derivative, etc.  D[f] is the "zeroth" derivative, 
i.e. it does nothing.

> Now, doing
> Plot[D[ArcTan[x], x], {x, -10, 10}, PlotRange -> Full]
> gives error messages such as 
> 
> General::ivar: -9.18326 is not a valid variable. >>
> General::ivar: -9.59143 is not a valid variable. >>, etc.
> 
> I thought that D[ArcTan[x], x] and 1/(x^2+1) should behave identically
> in the Plot statement.
> 
> Is this behavior something I should know? 
> 

Yes, this is related to evaluation order and the Hold* attributes.  Plot 
has the HoldAll attribtue, i.e. its arguments do not get evaluated 
before Plot sees them.  So Plot substitutes a number for x in 
D[ArcTan[x],x], and not in 1/(x^2+1).

Two solutions:

Plot[Evaluate[D[ArcTan[x], x]], {x, -10, 10}]

or

Plot[D[ArcTan[x],x], {x,-10,10}, Evaluated->True]


  • Prev by Date: Re: Problem with parametric minimization
  • Next by Date: Re: Anomaly? or at least a surprise.
  • Previous by thread: Re: Anomaly? or at least a surprise.
  • Next by thread: Re: Anomaly? or at least a surprise.