Stopping sliders in Manipulate going to dynamic unfeasible regions

I am trying to use Manipulate to create a function which allows a user to play with a probability density. The following generates a static density over the range 2000 - 4000, then allows the user to calculate the probability that the variable lies between two bounds: $aLower$ and $aUpper$:

fShowInterval[aLower_, aUpper_] :=
Module[{dist, p1, p2},
dist = PDF[UniformDistribution[{2000, 4000}], #] &;
p1 = Plot[dist@x, {x, aLower, aUpper}, Filling -> Axis,
FillingStyle -> Blue, BaseStyle -> {FontSize -> 16},
PlotStyle -> {Gray, Thickness[0.005]},
AxesLabel -> {"value $", "probability density "}, PlotRange -> {{1500, 4500}, Full}, Ticks -> {True, False}, PlotLabel -> N[(1/2000)*(aUpper - aLower)]]; p2 = Plot[dist@x, {x, 1500, 4500}, Filling -> None, PlotRange -> {{1500, 4500}, Full}, BaseStyle -> {FontSize -> 16}, PlotStyle -> {Gray, Thickness[0.005]}, AxesLabel -> {"value$ ", "p(v)"}];
Show[p1, p2,
Epilog -> {{Dashed, Line[{{2000, 0}, {2000, 1/2000}}]}, {Dashed,
Line[{{4000, 0}, {4000, 1/2000}}]}}, ImageSize -> 600]]

Manipulate[
fShowInterval[aLower, aUpper], {aLower, 2000, aUpper - 1,
100}, {aUpper, 2001, 4000, 100}]


With a result like:

The first slider stops the lower bound being higher than the upper. However, there are no corresponding constraints on the upper slider; meaning that it is possible to move this slider so that the lower bound is above the upper. I have tried modifying the Manipulate statement to:

Manipulate[
fShowInterval[aLower, aUpper], {aLower, 2000, aUpper - 1,
100}, {aUpper, aLower+1, 4000, 100}]


However, I get a slew of errors, and the graph does not display.

• Manipulate[If[aLower > aUpper, aLower = aUpper - 1]; fShowInterval[aLower, aUpper], {aLower, 2000, 4000, 100}, {aUpper, 2001, 4000, 100}] Jun 18, 2015 at 18:16
• Possible duplicate of Interdependent controls in Manipulate and How to creat interrelated sliders. Notice also that this situation is mentioned in the tutorial on Advanced Manipulate Functionality where a solution similar to the one proposed above by @belisarius is mentioned. Jun 18, 2015 at 18:21

You can use IntervalSlider in version 10.0 and above. However, you need to explicitly tell Manipulate to use it.

Manipulate[
fShowInterval[Sequence @@ probRange], {probRange, 2000, 4000,
IntervalSlider, Method -> "Push", MinIntervalSize -> 1},
Initialization :> (probRange = {2500, 3500};)]


Method -> "Push"will keep the interval endpoints from crossing one another. MinIntervalSize -> 1 will keep the endpoints from touching each other.

With IntervalSlider you can also click drag the interval by selecting the region between the two endpoints. Not very interesting for this distribution but it will be for many others.

• That's really great - thanks! Best, Ben Jun 18, 2015 at 21:18