# The correct way of compute indicator function in Mathematica

$$X_1= \mathbb{1}_{[0,1]}$$ $$X_2= \mathbb{1}_{[0,\frac{1}{2}]}, X_3= \mathbb{1}_{[\frac{1}{2},1]},$$ $$X_4= \mathbb{1}_{[0,\frac{1}{3}]}, X_5= \mathbb{1}_{[\frac{1}{3},\frac{2}{3}]}, X_6= \mathbb{1}_{[\frac{2}{3},1]},$$

I need plot this function, what is the correct way to compute this result from Mathematica?

Plot[{1}, {x, 0, 1}]


I have simple function, but I don't know how plot of $$X_2= \mathbb{1}_{[0,\frac{1}{2}]}$$ for interval $$[0,1]$$. Also I am interesting about representing of few function on the same image.

• You might use UnitStep or SquareWave. Aug 31, 2019 at 7:41

k = 4;
xx = BlockMap[Boole[# <= t <= #2] & @@ # &, #, 2, 1] & /@ Subdivide /@ Range[k];

Column[Plot[#, {t, 0, 1}, Filling -> Axis, Frame -> True,
ImageSize -> 1 -> 300, AspectRatio -> 1/5, PlotTheme -> "Minimal"] & /@ xx] kglr gives the general solution using Iverson brackets (Boole[] in Mathematica), which are entirely equivalent to the indicator function. Alternatively, one could also use the UnitBox[] function. Using kglr's example:

With[{m = 6},
Column[Plot[#, {t, 0, 1}, AspectRatio -> 1/5, Filling -> Axis, Frame -> True,
ImageSize -> 1 -> 300, PlotRange -> {0, 1}, PlotTheme -> "Minimal"] & /@
Table[UnitBox[k t - j - 1/2], {k, m}, {j, 0, k - 1}]]] Another function equivalent to UnitBox[k t - j - 1/2] is BSplineBasis[0, 0, k t - j].