MathGroup Archive 2003

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

Search the Archive

RE: Variable number of intervals

  • To: mathgroup at smc.vnet.net
  • Subject: [mg40489] RE: [mg40437] Variable number of intervals
  • From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
  • Date: Tue, 8 Apr 2003 03:02:39 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

>-----Original Message-----
>From: vnagornyi at netscape.net [mailto:vnagornyi at netscape.net]
To: mathgroup at smc.vnet.net
>Sent: Saturday, April 05, 2003 11:00 AM
>To: mathgroup at smc.vnet.net
>Subject: [mg40489] [mg40437] Variable number of intervals
>
>
>Hello,
>here is the function that grows on unit interval in 12 steps:
>
>n=12;
>Map[(g[x_]:=#/n/;(#-1)/n<=x<=#/n)&,Range[n]];
>Plot[g[x], {x,0,1}]
>
>Now, changing n in the first line we can get different number of
>steps.
>Instead, I would like to make n the function parameter: g[x_,n_] and
>define it when plotting, like
>
>Plot[{g[x,3],g[x,7],g[x,12]}, {x,0,1}]
>
>How to to this?
>Thanks.
>Vadim.
>

Vadim,

why not just

g[x_, n_] := Ceiling[x*n]/n

Plot[{g[x, 3], g[x, 7], g[x, 12]}, {x, 0, 1}, 
  PlotStyle -> Hue /@ (Range[3]/3)]


Conditional definitions are not simple to use in this case, although
possible:

In[61]:= Clear[g, n]
In[62]:=
g[x_, n_] := (Scan[(g[x$_, n] := #/n /; (# - 1)/n <= x$ <= #/n) &,
Range[n]]; 
    g[x, n])

In[63]:= g[.4, 3]
Out[63]= 2/3

In[64]:= ?g
Global`g
g[x$_, 3] := 1/3 /; (1 - 1)/3 <= x$ <= 1/3,
g[x$_, 3] := 2/3 /; (2 - 1)/3 <= x$ <= 2/3},
g[x$_, 3] := 3/3 /; (3 - 1)/3 <= x$ <= 3/3},
g[x_, n_] := (Scan[((g[x$_, n] := #1/n /; (#1 - 1)/n <= x$ <= #1/n)) &,
Range[n]]; g[x, n])           

In[66]:=
Plot[{g[x, 3], g[x, 7], g[x, 12]}, {x, 0, 1}, 
  PlotStyle -> Hue /@ (Range[3]/3)]



--
Hartmut Wolf



  • Prev by Date: Re: Re: Super-Increasing List
  • Next by Date: Re: Super-Increasing List
  • Previous by thread: Re: Variable number of intervals
  • Next by thread: Super-Increasing List