Re: Problems with differentiating Piecewise functions

• To: mathgroup at smc.vnet.net
• Subject: [mg86966] Re: Problems with differentiating Piecewise functions
• From: "David W.Cantrell" <DWCantrell at sigmaxi.net>
• Date: Thu, 27 Mar 2008 08:19:54 -0500 (EST)
• References: <fsd6ph\$9hb\$1@smc.vnet.net>

```hlovatt <howard.lovatt at gmail.com> 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?

It's not a "problem"; Mathematica's result is correct because your function
is not differentiable at 0. (Note that, at 0, the derivatives from left and
right are 0 and 1, resp.)

Consider an example in which the function _is_ differentiable at the join
between the pieces:

In[16]:= D[Piecewise[{{x^2, x <= 0}, {x^3, x > 0}}], x]

Out[16]= Piecewise[{{2*x, x < 0}, {0, x == 0}}, 3*x^2]

This is also handled correctly by Mathematica.

David

```

• Prev by Date: Re: Problems with differentiating Piecewise functions
• Next by Date: Re: Problems with differentiating Piecewise functions
• Previous by thread: Re: Problems with differentiating Piecewise functions
• Next by thread: Re: Problems with differentiating Piecewise functions