MathGroup Archive 1995

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

Search the Archive

Re: UnitStep Argument

  • To: mathgroup at christensen.cybernetics.net
  • Subject: [mg672] Re: [mg628] UnitStep Argument
  • From: bob Hanlon <hanlon at pafosu2.hq.af.mil>
  • Date: Sat, 8 Apr 1995 10:03:59 +45722824 (EDT)

On Fri, 7 Apr 1995, bob Hanlon wrote:

> On Sat, 1 Apr 1995, Roger M. Jones wrote:
> 
> > How can I define
> > UnitStep[-x], so that the answer is zero
> > (.i.e. assign x as being a positive number).
> > Defining: 
> > 
> > x/:Positive[x]=True doesn't work.
> > 
> > 
> > Many thanks.
> > 
> > ---
> > Regards,
> > 
> > Roger
> > (rmj at llewelyn.slac.stanford.edu)
> > 
> 
> Here are two simple approaches:
> 
> In[1]:=
> z /: Positive[z] = True;
> 
> In[2]:=
> UnitStep1[-x_] := 1 - UnitStep1[x];
> UnitStep1[x_] := If[Positive[x], 1, 0];
> 
> In[4]:=
> {UnitStep1[-4], UnitStep1[-0], UnitStep1[0], UnitStep1[4], 
> 	UnitStep1[-z], UnitStep1[z], UnitStep1[-y], UnitStep1[y]}
> 
> Out[4]=
> {0, 0, 0, 1, 0, 1, 1 - If[Positive[y], 1, 0], If[Positive[y], 1, 0]}
> 
> In[5]:=
> UnitStep2[-x_] := 1 - UnitStep2[x];
> UnitStep2[x_?Positive] := 1;
> UnitStep2[x_?Negative] := 0;
> UnitStep2[x_ /; x == 0] := 0;
> 
> In[9]:=
> {UnitStep2[-4], UnitStep2[-0], UnitStep2[0], UnitStep2[4], 
> 	UnitStep2[-z], UnitStep2[z], UnitStep2[-y], UnitStep2[y]}
> 
> Out[9]=
> {0, 0, 0, 1, 0, 1, 1 - UnitStep2[y], UnitStep2[y]}
> 
> 

There is a problem with the solutions which I provided as shown below.

In[1]:=
z /: Positive[z] = True;

UnitStep1[-x_] := 1 - UnitStep1[x];
UnitStep1[ x_] := If[ Positive[x], 1, 0 ];

In[4]:=
{ UnitStep1[-4], UnitStep1[0], UnitStep1[4],
	UnitStep1[z], UnitStep1[-z], UnitStep1[y], UnitStep1[-y],
	UnitStep1[-y /. y -> 0], UnitStep1[-y] /. y -> 0 }

Out[4]=
{0, 0, 1, 1, 0, If[Positive[y], 1, 0], 1 - If[Positive[y], 1, 0], 
 
  0, 1}

Note that the substitutions in the last two cases above give conflicting 
results.  The same problem exists for UnitStep2:

UnitStep2[-x_] := 1 - UnitStep2[x];
UnitStep2[ x_?Positive ]  := 1;
UnitStep2[ x_?Negative ]  := 0;
UnitStep2[ x_ /; x == 0 ] := 0;

In[9]:=
{ UnitStep2[-4], UnitStep2[0], UnitStep2[4],
	UnitStep2[z], UnitStep2[-z], UnitStep2[y], UnitStep2[-y],
	UnitStep2[-y /. y -> 0], UnitStep2[-y] /. y -> 0 }

Out[9]=
{0, 0, 1, 1, 0, UnitStep2[y], 1 - UnitStep2[y], 0, 1}

The following definition, UnitStep3, provides consistent results:

UnitStep3[-x_ /;  Positive[x] ] := 0;
UnitStep3[ x_ /;  Positive[x] ] := 1;
UnitStep3[ x_ /; !Positive[x] ] := 0;

In[13]:=
{ UnitStep3[-4], UnitStep3[0], UnitStep3[4],
	UnitStep3[z], UnitStep3[-z], UnitStep3[y], UnitStep3[-y],
	UnitStep3[-y /. y -> 0], UnitStep3[-y] /. y -> 0 }

Out[13]=
{0, 0, 1, 1, 0, UnitStep3[y], UnitStep3[-y], 0, 0}





  • Prev by Date: Re: WWW sites
  • Next by Date: Re: Re: SuperPrimes
  • Previous by thread: Re: UnitStep Argument
  • Next by thread: plotting roots of complex nonlinear equation