11

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.'

kglr
  • 394,356
  • 18
  • 477
  • 896
WalkingRandomly
  • 4,107
  • 1
  • 20
  • 36

1 Answers1

15

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}}]
Pinguin Dirk
  • 6,519
  • 1
  • 26
  • 36
  • 2
    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... – Albert Retey Mar 12 '13 at 09:19
  • @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? – István Zachar Jun 07 '17 at 11:55
  • @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... – Albert Retey Jun 07 '17 at 12:37
  • 1
    @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"}] – garej May 11 '18 at 20:38
  • @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. – István Zachar May 14 '18 at 09:49