I was looking at the Documentation Center for Round
, Ceiling
and Floor
when I noticed that the plots for Round
showed some variation, even at the small size that the Documentation Center displays them, when blown up... well:
Plot[Round[x, 10], {x, -30, 30}, Filling -> Axis]
Plot[Round[x], {x, -3, 3}, Filling -> Axis]
This intrigued me, I don't fully understand the rules governing generation of plots from functions. Clearly the method is adaptive, generating more data points where there is "activity," but is the (dis)continuity just based on the resolution that the plot is generated using?
Any insight is welcome.
Answer
This is probably not a complete answer. Plot
attempts at some point to detect discontinuities symbolically. With a few built-ins, it can do it. Round[x]
is an example but for some reason Round[x, 1]
is not
Those discontinuities are excluded from the plots (see Exclusions
)
So, for example, compare the output of these
Plot[Round[x], {x, -3, 3}]
Plot[Round[x, 1], {x, -3, 3}]
If you define r[x_?NumericQ]:=Round[x]
, then r[x]
behaves the same way as Round[x, 1]
because it doesn't know how to manipulate your custom r
symbolically
Now, if Plot
already knows beforehand it has a discontinuity somewhere, it can be smarter than usual. For example, it can try to make the discontinuities sharper by sampling right on the sides.
x1 = Reap[
Plot[Round[x, 1], {x, -3, 3}, Filling -> Axis,
EvaluationMonitor -> Sow[x]]][[-1, 1]] // Rest;
x2 = Reap[
Plot[Round[x], {x, -3, 3}, Filling -> Axis,
EvaluationMonitor -> Sow[x]]][[-1, 1]] // Rest;
Complement[x2, x1]
{-2.50191, -2.49809, -1.50191, -1.49809, -0.501913, -0.498087, \ 0.498087, 0.501913, 1.49809, 1.50191, 2.49809, 2.50191}
As to the rendering issues with the Filling
, that's because it excludes discontinuities by default. Try with Exclusions->None
Plot[Round[x], {x, -3, 3}, Filling -> Axis, Exclusions -> None]
Related question: Managing Exclusions in Plot[ ]
Comments
Post a Comment