MathGroup Archive 2003

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

Search the Archive

Re: Variable number of intervals

  • To: mathgroup at smc.vnet.net
  • Subject: [mg40466] Re: [mg40437] Variable number of intervals
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Mon, 7 Apr 2003 04:53:32 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

The easiest and most efficient way to do this is using UnitStep but as 
I am sure others will post this solution let me just point out that you 
can directly adapt your presnt code with:

In[1]:=

g[x_,n_]:=Block[{g,y},Map[(g[y_]:=#/n/;(#-1)/n<=y<=#/n)&,Range[n]];g[x]]


You can now do what you wanted:

In[2]:=
Plot[{g[x,3],g[x,7],g[x,12]},{x,0,1}]

to get a rather curious graph.

It maybe slightly more efficient to use Scan instead of Map, since it 
works in exactly the same way but produces no output.

Andrzej Kozlowski
Yokohama, Japan
http://www.mimuw.edu.pl/~akoz/
http://platon.c.u-tokyo.ac.jp/andrzej/



On Saturday, April 5, 2003, at 06:00  pm, Vadim Nagornyi wrote:

> 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.
>
>
>



  • Prev by Date: Re: Import - FITS
  • Next by Date: Re: dynamic programming inside a function
  • Previous by thread: Re: Variable number of intervals
  • Next by thread: RE: Variable number of intervals