# Use slider controls to set function domain of plotted function

I want to display Plot[f,{t, t1, t2}] in a Manipulate with the domain {t1, t2} specified by slider controls with something like

Manipulate[
Plot[t^2, {t, t1, t2}],
{{t1, -1, "t1"}, -2, 2, 0.1},
{{t2, 1, "t2"}, -2, 2, 0.1}]


In particular, I want to require t1 < t2 and to display a warning if t1 = t2 or t1 > t2. Although the above code produces an error when t1 = t2, Mathematica appears to switch the roles of t1 and t2 when the sliders are set to t1 > t2.

I have tried the control statements

{{t1, -1, "t1"}, -2, 2, 0.1},
{{t2, 1, "t2"}, t1, 2, 0.1}


but to no avail.

An alternative solution is just to eliminate the sliders and instead provide input fields for t1 and t2.

• Have you considered If[t1 < t2, Plot[...], warning]? Put it inside a Pane to control ImageSize if desired. Aug 15 '15 at 12:01
• I replaced the Plot statement with Pane[If[ t1 < t2, Plot[t^2, {t, t1, t2}], Style["Require t2 > t1"]]. That works nicely. Aug 15 '15 at 12:32
• You could put your comment into an answer. :) Also, if you have V10, then there's [IntervalSlider](http://reference.wolfram.com/language/ref/IntervalSlider.html), which might help you avoid the issue entirely, if that would be preferable. Aug 15 '15 at 12:40
• @Michael E2: IntervalSlider - a great solution! Aug 15 '15 at 13:00

There are couple of ways to handle your problem.

Simple -- give a warning of slider interference:

Manipulate[
If[t1 < t2, Plot[t^2, {t, t1, t2}], "Warning: t1 > t2"],
{{t1, -1}, -2, 2, 0.1, Appearance -> "Labeled"},
{{t2, 1}, -2, 2, 0.1, Appearance -> "Labeled"}]


More elegant user interface, less elegant code -- prevent slider interference:

I have to give up Manipulate's simple control specification format for the sliders because I want to use the second argument of Dynamic to constrain the slider thumbs.

Manipulate[
Plot[t^2, {t, t1, t2}],
Row[{
"t1 ",
Slider[Dynamic[t1, (t1 = If[# >= t2, t1, #]) &], {-2, 2, 0.1},
Appearance -> "Labeled"]}],
Row[{
"t2 ",
Slider[Dynamic[t2, (t2 = If[# <= t1, t2, #]) &], {-2, 2, 0.1},
Appearance -> "Labeled"]}],
{{t1, -1}, None},
{{t2, 1}, None}]


I prefer the second method because I believe it is better to prevent bad things from happening than to give warnings that they have happened.