MathGroup Archive 2003

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

Search the Archive

Re: Defining function in loop

  • To: mathgroup at smc.vnet.net
  • Subject: [mg40446] Re: Defining function in loop
  • From: Bill Rowe <listuser at earthlink.net>
  • Date: Sat, 5 Apr 2003 04:01:55 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

On 4/4/03 at 1:27 AM, vnagornyi at netscape.net (Vadim Nagornyi) wrote:

>Hello, I am definihg step-like function
>
>Clear[h] 
h[x_] := 0/;x<0 
h[x_] := 1/;0<=x<=1
h[x_] := 2/;1<=x<=2
h[x_] := 3/;2<=x<=3 
h[x_] := 4/;x>3

>It works fine:

>Table[h[x],{x,-1,4,.5}] 
>{0, 0, 1, 1, 1, 2, 2, 3, 3, 4, 4}

>As I may need more steps, I am trying to do the same in loop:

While I am sure there is a way to do it in a loop this is certainly not the easiest way

Try

f[x_, n_]:= Sum[UnitStep[x-k], {k,0,n}]
Table[f[x,3], {x,-1,4,0.5}]
{0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4}



  • Prev by Date: Re: Parallel Kit Question: ParallelDot is much more slow than Dot
  • Next by Date: Re: Defining function in loop
  • Previous by thread: Defining function in loop
  • Next by thread: Re: Defining function in loop