Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Re: Problems with differentiating Piecewise functions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg86967] Re: Problems with differentiating Piecewise functions
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Thu, 27 Mar 2008 08:20:05 -0500 (EST)
  • Organization: The Open University, Milton Keynes, UK
  • References: <fsd6ph$9hb$1@smc.vnet.net>

hlovatt wrote:

> If I set up a piecewise function and differentiate it:
> 
> In[112]:= pw1 = Piecewise[{{x^2, x <= 0}, {x, x > 0}}]
> 
> Out[112]= \[Piecewise] {
>   {x^2, x <= 0},
>   {x, x > 0}
>  }
> 
> In[113]:= pw1 /. x -> 0
> 
> Out[113]= 0
> 
> In[114]:= pw1d = D[pw1, x]
> 
> Out[114]= \[Piecewise] {
>   {2 x, x < 0},
>   {1, x > 0},
>   {Indeterminate, \!\(\*
>      TagBox["True",
>       "PiecewiseDefault",
>       AutoDelete->False,
>       DeletionWarning->True]\)}
>  }
> 
> In[115]:= pw1d /. x -> 0
> 
> Out[115]= Indeterminate
> 
> Then at the joins between the pieces I get Indeterminate values,
> because the limit x <= 0 has become x < 0 after differentiation. Does
> anyone know a solution to this problem?


Mathematica is perfectly correct in claiming that the derivative of pw1 
at x equals zero, i.e. pw1d(0), does not exist (or undefined or 
indeterminate).

For a derivative at a point is the *limit*, _if this limit exists_, of a 
difference quotient, that is the limit on the right and the limit on the 
left to the point must be equal.

Or think of the derivative as the slope of the tangent to the curve: the 
slope of the tangent must be the same on the right and on the left, for 
a given point.

A classical example of an elementary function continuous but not 
differentiable at zero is the absolute value function. The slope of the 
tangent is -1 for all negative values and +1 for all positive values, 
thus the derivative does not exist at 0.

I would advise to brush up some of your calculus, for instance by 
looking at the entry "Derivative", especially the section titled 
"Continuity and differentiability" in Wikipedia (or in any Calculus 
book). See http://en.wikipedia.org/wiki/Derivative

(Note that the example you provided comes from the online help, and it 
is very unlikely that WRI publishes erroneous examples.)


Regards,
-- 
Jean-Marc


  • Prev by Date: Re: Counting nonzeros
  • Next by Date: Re: Another stylesheet question
  • Previous by thread: Re: Problems with differentiating Piecewise functions
  • Next by thread: Re: Re: Problems with differentiating Piecewise functions