2
$\begingroup$

I'm trying to use NumberLinePlot and Manipulate to visualize how the interval $[t-1, t] \cap [0, 1]$ changes as the value of $t$ changes. My code is:

Manipulate[NumberLinePlot[{Interval[{0, 1}], Interval[{t - 1, t}]}, PlotRange -> {-3, 3}], {t, -3, 3}]

which gives a result that looks like this: enter image description here My question is: how can I make Mathematica tell me explicitly what the intersection is? For example, with the slider positioned as in the picture, I would want it to print something like $[0, 0.6]$

$\endgroup$
1

2 Answers 2

4
$\begingroup$

Mathematica graphics

Manipulate[
 Module[{int1, int2},
  int1 = Interval[{0, 1}];
  int2 = Interval[{t - 1, t}];
  
  Grid[{{IntervalIntersection[int1, int2]},
    {NumberLinePlot[{int1, int2}, PlotRange -> {-3, 3}]}
    }]
  ],
 {t, -3, 3}, TrackedSymbols :> {t}]
$\endgroup$
3
$\begingroup$

Some embellishments on answer by @Nasser

Clear["Global`*"]

Manipulate[Module[{int}, int[1] = Interval[{0, 1}];
  int[2] = Interval[{t - 1, t}];
  int[3] = IntervalIntersection[
    int[1], int[2]];
  Grid[{
    {If[int[3] === Interval[],
      Nothing, int[3]]}, {NumberLinePlot[int /@ {1, 2, 3},
      PlotRange -> {-2, 3}]}}]], {{t, 0.5}, -1, 3, 0.01,
  Appearance -> "Labeled"}, TrackedSymbols :> {t}]

enter image description here

$\endgroup$

Your Answer

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

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