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$
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}}]
|improve this answer|||||
$\endgroup$
  • 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$ – Albert Retey Mar 12 '13 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$ – István Zachar Jun 7 '17 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$ – Albert Retey Jun 7 '17 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 May 11 '18 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$ – István Zachar May 14 '18 at 9:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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