6
$\begingroup$

$$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.

$\endgroup$
1
  • 2
    $\begingroup$ You might use UnitStep or SquareWave. $\endgroup$ Aug 31, 2019 at 7:41

2 Answers 2

8
$\begingroup$
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]

enter image description here

$\endgroup$
2
$\begingroup$

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}]]]

indicator functions

Another function equivalent to UnitBox[k t - j - 1/2] is BSplineBasis[0, 0, k t - j].

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.