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?