MathGroup Archive 2005

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

Search the Archive

Re: [Newbie] Interpreting output

  • To: mathgroup at smc.vnet.net
  • Subject: [mg56651] Re: [mg56642] [Newbie] Interpreting output
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Sun, 1 May 2005 03:13:33 -0400 (EDT)
  • References: <200505010446.AAA13098@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On 1 May 2005, at 13:46, MC wrote:

> Hi everybody....
>
> I'm having troubles in interpreting the output of Mathematica.
>
> My problem is to define a function F(x,y,z) such that:
> F = (whatever) if x>c
> F=(whatever) if x<=c
>
> I achievied this using /;
>
> When I derive F with respect to one of the variables, the result is a 
> mess.
> Just an example with 1 variable:
>
> f=x/;x>0;
> f=-x^2/;x<0;
>
> D[f,x]=-2Condition(1,0)[x^2,x<0]+Condition(1,0)[x^2,x<0]Less(1,0)[x,0]
>
> Even in this very simple case, the result is a real mess:
> I really do not know how should I read that...and I'm wondering if
> I have defined the function in the right way.
>
> Anybody so kind to explain me what's goung on?
>
> Thank you very much for your patience
>
>

What is going on is simply that you that Mathematica's notion of 
derivative does not work with piecewise functions defined by means of 
pattern matching. (Actually, there is nothing in the documentation that 
suggests that it might.)
In order for differentiation to be possible you have to construct a 
piecewise function using a construction that "understands" the notion 
of a derivative. In Mathematica 5.1 this is easy:

f[x_] := Piecewise[{{x^2, x < 2}, {x^3, x >= 2}}]

f'[1]
2


f'[3]
27


f'[2]
Indeterminate


In earlier version you could try doing this by means of the UnitStep 
function:

g[x_] := x^2*UnitStep[2 - x] + x^3*UnitStep[x - 2]

this will work almost the same except for the singular value


g'[1]
2


g'[3]

27



g'[1]

2


g'[3]

27


g'[2]


4*DiracDelta[0] + 16


Note also that both approaches work well when you construct a 
differentiable everywhere piecewise function:


f[x_] := Piecewise[{{(x-1)^2, x < 1}, {(x-1)^3, x >= 1}}]


f'[1]
0


g[x_]:=(x-1)^2*UnitStep[1-x]+(x-1)^3*UnitStep[x-1]


g'[1]

0

However, this is achieved in a quite different way, which we can see 
from


f'[x]

Piecewise[{{2*(x - 1), x < 1}, {0, x == 1}}, 3*(x - 1)^2]


and


g'[x]

DiracDelta[x - 2]*(x - 2)^3 - DiracDelta[x - 2]*
    (x - 2)^2 + 3*UnitStep[x - 2]*(x - 2)^2 +
   2*UnitStep[2 - x]*(x - 2)


The second answer is given as a "generalized function" and although it 
seems "correct" I would not rely on this type of use  of generalised 
functions (distributions) in anything but the most simple types of 
situations. The Piecewise approach looks more promising.



Andrzej Kozlowski
Chiba, Japan
http://www.akikoz.net/andrzej/index.html
http://www.mimuw.edu.pl/~akoz/


  • Prev by Date: Re: [Newbie] Interpreting output
  • Next by Date: ndsolve error message
  • Previous by thread: Re: [Newbie] Interpreting output
  • Next by thread: Re: Interpreting output