Re: Problems with differentiating Piecewise functions
- To: mathgroup at smc.vnet.net
- Subject: [mg86938] Re: Problems with differentiating Piecewise functions
- From: Szabolcs Horvát <szhorvat at gmail.com>
- Date: Thu, 27 Mar 2008 08:14:39 -0500 (EST)
- Organization: University of Bergen
- 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?
Mathematically it makes sense. The derivative cannot be defined in that
point. You could manually replace Indeterminate with whichever value
you need there:
D[pw1, x] /. Indeterminate -> a
or
D[pw1, x] /. Indeterminate -> 0