11
$\begingroup$

Is it possible to easily modify a Manipulate such that the slider automagically skips certain values?

For example, say I am plotting an equation that's perfectly well behaved for all values of x between x=0 and x=1 except for x=0.25 where it blows up and causes Mathematica to emit many error messages. I could, of course, check for x=0.25 in the body of the Manipulate and then do something sensible but it would be nice if I could just say to Manipulate 'Avoid x=0.25.'

$\endgroup$

1 Answer 1

15
$\begingroup$

It seems to me that this works:

Manipulate[1/(x - 0.25), {x, 0, 1, Exclusions -> {0.25}}]

(Exclusions is from Slider, I just tried it here and seems to do the job)

or slightly more clear:

Manipulate[1/(x - 0.25), {x, 0, 1, 0.25, Exclusions -> {0.25}}]
$\endgroup$
5
  • 2
    $\begingroup$ What Manipulate uses as default control for numeric values is a Manipulator which also has the Exclusions option and is called exactly like a Slider... $\endgroup$ Commented Mar 12, 2013 at 9:19
  • $\begingroup$ @Albert, Pinguin. This does not work: Manipulate[x, {{x, .5}, 0, 1, Exclusions -> {0.}, Appearance -> "Labeled"}]. Any idea why? Because one cannot exclude values that were specified in the slider's range? $\endgroup$ Commented Jun 7, 2017 at 11:55
  • $\begingroup$ @IstvánZachar: our assumption might well be correct, it neither seems to be the special value of 0 nor the Appearance option, but I don't know. As too often, documentation isn't giving a hint what to expect in corner cases. It also seems that only using the slider respects the Exclusions option, if you enter the excluded value into the input box then it will be set anyway... $\endgroup$ Commented Jun 7, 2017 at 12:37
  • 1
    $\begingroup$ @IstvánZachar, it wants a step to change from exclusion value. So, this works: Manipulate[x, {{x, .5}, 0, 1, 0.01, Exclusions -> {0.}, Appearance -> "Labeled"}] $\endgroup$
    – garej
    Commented May 11, 2018 at 20:38
  • $\begingroup$ @garej Oh, that makes perfect sense. Without a stepsize, it does not now how to handle real values arbitrarily close to the exclusion. Thanks for the info. $\endgroup$ Commented May 14, 2018 at 9:49

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.