Hello,
I need to implement a piecewise function composed of many separate functions defined over many subintervals. I am looking for a construct that would allow me to achieve this goal in a compact way by using some loop (say For[] or Do[] ) for checking which function to select for a given value of an argument. Is there any way to do this? Implementations involving Which[] or Piecewise[] all require
writing a long sequence of conditions and expressions for the particular functions, which is somewhat inconvenient. In addition, if new subintervals are added, one has to modify the code for the piecewise function. For example, in the case of three subintervals, one can write:
Fun[x_]:=Which[
x>a[1] && x<=b[1], f[1][x],
x>a[2] && x<=b[2], f[2][x],
x>a[3] && x<=b[3], f[3][x]
];
but this becomes awkward if there are several dozens of subintervals, so that some loop construct might be simpler, if this is possible. Please note that the interval bounds and functions f[] are all indexed.
Lesław