Re: Variable number of intervals
- To: mathgroup at smc.vnet.net
- Subject: [mg40458] Re: [mg40437] Variable number of intervals
- From: Dr Bob <majort at cox-internet.com>
- Date: Sun, 6 Apr 2003 04:34:51 -0400 (EDT)
- References: <200304050900.EAA16237@smc.vnet.net>
- Reply-to: majort at cox-internet.com
- Sender: owner-wri-mathgroup at wolfram.com
g[x_, n_Integer] := Sum[UnitStep[x - k/n]/n, {k, 0, n - 1}]
or (simpler, more efficient, and not limited to the unit interval)
g[x_, n_Integer] := Ceiling[n x]/n
The first is right-continuous while the second is left-continuous.
The function is useful for creating various square waves:
Plot[g[x, 24] - g[x, 12], {x, 0, 1}]
Plot[g[x, 12] - g[x, 24] + g[x, 48] - g[x, 96], {x, 0, 1}]
Bobby
On Sat, 5 Apr 2003 04:00:25 -0500 (EST), Vadim Nagornyi
<vnagornyi at netscape.net> 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.
>
>
--
majort at cox-internet.com
Bobby R. Treat
- References:
- Variable number of intervals
- From: vnagornyi@netscape.net (Vadim Nagornyi)
- Variable number of intervals