Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #14354 > unrolled thread

Re: how to generate piecewise function from two lists

Started byFred Simons <f.h.simons@tue.nl>
First post2013-04-28 09:17 +0000
Last post2013-04-28 09:17 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: how to generate piecewise function from two lists Fred Simons <f.h.simons@tue.nl> - 2013-04-28 09:17 +0000

#14354 — Re: how to generate piecewise function from two lists

FromFred Simons <f.h.simons@tue.nl>
Date2013-04-28 09:17 +0000
SubjectRe: how to generate piecewise function from two lists
Message-ID<klipf1$11v$1@smc.vnet.net>
This is straightforward using the function Partition:

In[21]:= f={a,b};
r={0,1,2};
With[{rr=Partition[r,2,1]},
Piecewise[Table[{f[[i]], rr[[i,1]]<x<rr[[i,2]]}, {i,1,Length[f]}]]] // 
InputForm

Out[23]//InputForm=
Piecewise[{{a, 0 < x < 1},   {b, 1 < x < 2}}, 0]

Fred Simons
Eindhoven University of Technology




Op 28-4-2013 7:00, S schreef:
> 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
>
>
>
> -----
> Geen virus gevonden in dit bericht.
> Gecontroleerd door AVG - www.avg.com
> Versie: 2013.0.3272 / Virusdatabase: 3162/6277 - datum van uitgifte: 04/27/13
>
>

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web