Skip to main content
Tweeted twitter.com/#!/StackMma/status/455756698326958080
edited title
Link
m_goldberg
  • 108.1k
  • 16
  • 104
  • 259

Why do plot commands evaluate How can I prevent a Plot expression from evaluating points forbidden by their RegionFunctionsits RegionFunction?

Source Link
Emilio Pisanty
  • 10.3k
  • 1
  • 37
  • 71

Why do plot commands evaluate points forbidden by their RegionFunctions?

I just ran into this and it had me scratching my head for a good while. Say I have a function which may produce error messages for certain inputs, like e.g.

f[x_, y_] := (Sin[x] - Sin[y])/(x - y)

which will return Power::infy and Infinity::indet when called on the diagonal x==y. If I want to avoid that singular input in a plot, the standard way of telling Mathematica to not evaluate it there is to use a RegionFunction command, like

Plot3D[f[x, y]
 , {x, -10, 10}, {y, -10, 10}
 , RegionFunction -> Function[{x, y, f}, Abs[x - y] > 5]
 ]

This will successfully generate a plot with the diagonal taken off, but it will still produce the same error messages as f[1,1]. This behaviour remains even if I add the qualifiers f[x_: NumericQ, y_: NumericQ] to the definition, so some singular inputs are definitely passed to the function even though they are away from where I'm telling it to plot.

So: why is this? Is this actually the correct way to specify regions to stay away from? If not, what's the best practice for that?