# Plot of function with undefined value

I'm tinkering with Mathematica and plotted this function today:

d = 0.000001
Plot[y = (x^2 - 4)/(x - 2), {x, 2 - d, 2 + d}]


This function is undefined when x = 2, so I wanted to plot the area where x is really close to 2.

However the results were weird: In the place where I would expect to be an empty dot, I saw some wiggly stuff.

I "zoomed in" the function by making the d even smaller:

d = 0.0000001
Plot[y = (x^2 - 4)/(x - 2), {x, 2 - d, 2 + d}]


And got an even more surprising outcome: How can this be explained? I would expect a straight line and a "hole" in it where x=2.

What you are seeing is the interaction between machine arithmetic imprecision and the way Plot draws curves by drawing lines between a mesh of points it has computed as being on the curve. If the computation is done at low precision, the computed points don't follow the actual curve very well and you get jaggies. You can fix the jaggies by asking for more precision.

Before

With[{k = 7},
Plot[(x^2 - 4)/(x - 2), {x, 2 - 10^-k, 2 + 10^-k},
PlotRange -> {4 - 10^-k, 4 + 10^-k}] After

With[{k = 7},
Plot[(x^2 - 4)/(x - 2), {x, 2 - 10^-k, 2 + 10^-k},
PlotRange -> {4 - 10^-k, 4 + 10^-k},
WorkingPrecision -> 100]] d = 10^-7;
Table[Plot[y = (x^2 - 4)/(x - 2), {x, 2 - d, 2 + d},
WorkingPrecision -> p, PlotLabel -> p], {p, 7, 10, 1}] • @Valentin, depending on WorkingPrecision->p you can see an empty area at p=7, a hole at p=8, what you wanted to see at p=9 or a solid line at p=10. Do you want to know why this is so? – Alex Trounev Sep 24 '18 at 13:41