The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Inactive » comp.soft-sys.math.mathematica

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Re: how to generate piecewise function from two lists
Replies: 1   Last Post: Apr 30, 2013 4:17 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Ray Koopman

Posts: 3,383
Registered: 12/7/04
Re: how to generate piecewise function from two lists
Posted: Apr 28, 2013 5:17 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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

On Sat, Apr 27, 2013 @ 10:00 PM, S <> 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

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.