MathGroup Archive 2013

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

Search the Archive

Re: how to generate piecewise function from two lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg130651] Re: how to generate piecewise function from two lists
  • From: Ray Koopman <koopman at sfu.ca>
  • Date: Sun, 28 Apr 2013 05:18:15 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-outx@smc.vnet.net
  • Delivered-to: mathgroup-newsendx@smc.vnet.net

Piecewise[{#1, #2[[1]] < x < #2[[2]]}& @@@ Transpose@{f,Partition[r,2,1]}]

On Sat, Apr 27, 2013 @ 10:00 PM, S <dsalman96 at gmail.com> wrote:
> Hello
> 
> Suppose we have two lists
> f={a,b}
> r={0,1,2)
> 
> In general, the lengths of f and r can vary but the length of f is always 1 less than length of r.
> 
> Using the lists f and r, I want to define a piecewise function of the form:
> 
> Piecewise[{{a,0<x<1},{b,1<x<2}}] i.e., having the form
> 
> Piecewise[{{f[[1]],r[[1]]<x<r[[2]]},{f[[2]],r[[2]]<x<r[[3]]}}]
> 
> Is there a way to define a piecewise function using f and r for the general case, as described above.
> 
> Thanks
> 
> S



  • Prev by Date: Re: how to generate piecewise function from two lists
  • Next by Date: Re: combinations problem
  • Previous by thread: Re: how to generate piecewise function from two lists
  • Next by thread: Re: how to generate piecewise function from two lists