Re: UnitStep Argument
- To: mathgroup at christensen.cybernetics.net
- Subject: [mg663] Re: [mg628] UnitStep Argument
- From: bob Hanlon <hanlon at pafosu2.hq.af.mil>
- Date: Fri, 7 Apr 1995 23:15:34 (EDT)
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]}