I was trying to define a Piecewise function using a previously defined Interval
object (that is the union of several intervals). However, I realised that I wasn't getting the right behaviour when trying to either plot or evaluate the function. If I define the function using the lower and upper limits of the interval everything works correctly though.
Here is a simplified version of my code:
f = Piecewise[{{1, Element[x, Interval[{0, 1}]]}}, 0]
g = Piecewise[{{1, 0 < x < 1}}, 0]
When running
Plot[{f, g}, {x, 0, 2}]
only g is plotted and not f. The same happens if I try to evaluate the functions at a specific x value.
Why is that the case? Is it possible to use Piecewise
together with an Interval
object or should I always use the upper and lower limits?