# Plot of continuous function cuts off

Why the following plot cuts off at integer points ?

Plot[Cos[Pi IntegerPart[x]]
Min[Abs[FractionalPart[x]], Abs[FractionalPart[x] - 1]], {x, 0, 10}]


Update

It gets connected when you add Exclusions -> None as an option, but It is not clear why this function has exclusive points, since it is continuous. Also it gets connected if you increase the PlotPoints (thanks to the comments). Also why at x=9 the cut is more severe than say at x=1 or x=2 ?

Can someone explain what is the issue here, and how these two options solve(or maybe hide) the issue ?

• add the option Exclusions -> None? – kglr Apr 15 '17 at 21:36
• The gaps don't occur with "11.1.0 for Mac OS X x86 (64-bit) (March 16, 2017)" – Bob Hanlon Apr 15 '17 at 21:48
• add the option PlotPoints -> 500 helps – Bill Apr 16 '17 at 5:42
• I think this is an interesting question. I think that the function is continuous, so why are points excluded? – mikado Apr 16 '17 at 12:22
• The question is not "how can I make the plot continuous", but why the plot cuts off, and why at x=9 it is more severe than say at x=1 or x=2. As @mikado mentioned the function is continuous, then whats the issue ? – Mher Apr 16 '17 at 12:46

## 2 Answers

This behavior has been evolving ever since Mathematica was created. Something different happens in V11 than in V10. (I'm unable to go back further.) I'll describe V10 first, since its behavior conforms to the OP.

IN V10, the gaps are because the functions FractionalPart and IntegerPart are discontinuous, which makes the gaps symmetric. In plotting, Mathematica does not check limits at their discontinuities to see if the expression being plotted happens to be continuous. Rather, it assumes the discontinuities in the component functions propagate to discontinuities in the plot and puts a little gap in the plot at each one.

I assume this choice (not to check limits) was made for the sake of speed. The discontinuities are identified by a time-constrained symbolic analysis of the function.

The size of the gap is determined by the sampling. With higher setting for PlotPoints, the smaller the gap. The sampling can be observed using Mesh -> All. The sampling is a result of an asymmetric recursive subdivision of "active" subintervals, which depends principally on the angles between successive line segments used to approximate the graph. As a result, the gaps are not identical.

Plot[Cos[Pi IntegerPart[x]] Min[Abs[FractionalPart[x]],
Abs[FractionalPart[x] - 1]], {x, 0, 10}, Mesh -> All,
MeshStyle -> Red]


The gaps are not visible at ordinary size with lots of plot points:

Plot[Cos[Pi IntegerPart[x]] Min[Abs[FractionalPart[x]],
Abs[FractionalPart[x] - 1]], {x, 0, 10}, PlotPoints -> 1000]


Another approach, mentioned by @kglr in a comment, is to turn off the processing with Exclusions -> None.

Plot[Cos[Pi IntegerPart[x]] Min[Abs[FractionalPart[x]],
Abs[FractionalPart[x] - 1]], {x, 0, 10}, Exclusions -> None]


IN V11, Plot adds sampling points close to the discontinuity. It still does not connect the lines, but if the function is continuous, the gap should be imperceptible.

plot = Plot[
Cos[Pi IntegerPart[x]] Min[Abs[FractionalPart[x]], Abs[FractionalPart[x] - 1]],
{x, 0, 10}, Mesh -> All, MeshStyle -> Red]
Count[plot, _Line, Infinity]


(*  20  <-- number of continuous lines *)


One continuous line is created with Exclusions -> None:

Count[
Plot[Cos[Pi IntegerPart[x]] Min[Abs[FractionalPart[x]],
Abs[FractionalPart[x] - 1]], {x, 0, 10}, Exclusions -> None],
_Line, Infinity]
(*  1  <-- number of continuous lines *)


Another workaround is to define a numeric function, effectively hiding the (potential) discontinuities from Plot:

f[x_?NumericQ] := Cos[Pi IntegerPart[x]] Min[Abs[FractionalPart[x]],
Abs[FractionalPart[x] - 1]]
Plot[f[x], {x, 0, 10}]


Count[%, _Line, Infinity]


1

• – Rahul Apr 18 '17 at 1:03
• @Rahul. The "why" is because Plot "sees" the embedded discontinuous functions, as illustrated by hiding them and making the problem go away. Whats your point? – george2079 Apr 18 '17 at 11:36
• My point is only that your answer does not directly address the OP's question, except implicitly. – Rahul Apr 18 '17 at 12:57
• +1 this is interesting confirmation of the explanation given by @MichaelE2 – mikado Apr 18 '17 at 18:08