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}]
$\endgroup$