# How to plot functions with large slope on a compact domain?

The Mathematica command Plot[(1 - r^2)^(1/32), {r, -1, 1}] does not plot the function near the boundary points. That is, the graph does not attain 0 at r = +-1. Increasing WorkingPrecision and PlotPoints does not seem to help. How does one fix the graph to match the function?

One way is to use ListLinePlot:

ListLinePlot@Table[{r, (1 - r^2)^(1/32)}, {r, -1, 1, 1/100}]


Plot uses open sampling to avoid singularities at endpoints:

Cases[Plot[x^2, {x, 0, 1}], Line[p_] :> First@p, Infinity]
Cases[Plot[1/x, {x, 0, 1}, PlotRange -> All], Line[p_] :> First@p, Infinity]
(* both yield  {{2.04082*10^-8, 4.16493*10^-16}}  *)


Alternative

ParametricPlot does not seem to use open sampling, although it seems to choose a plot range based on the density of plotted points, excluding the two endpoints with default PlotRange:

ParametricPlot[{r, (1 - r^2)^(1/32)}, {r, -1, 1},
PlotRange -> {{-1, 1}, {0, 1}}, PlotRangePadding -> Scaled[.02]]


• That's a way out, I agree, but suddenly I find myself wondering, why Plot outright refuses to sample the endpoints. – LLlAMnYP May 13 '15 at 15:48
• Great solution, great explanation. Thanks! It would be nice to explore LLlAMnYP's train of thought as a collection of these curves is the output. This makes for a larger pdf file. – dantopa May 13 '15 at 16:04
• @dantopa 1) Thanks. It used to be that Plot sampled the end points and complained bitterly about undefined functions etc. I think user complaints led WRI to change the default behavior to make it easier to plot Log, Tan, 1/x etc. 2) See alternative. 3) You might want to wait a day before accepting (thanks, though!) since there may be better answers; not having a accepted answer might encourage others to try out their ideas. – Michael E2 May 13 '15 at 16:21
• @Michael E2 ParametricPlot is the ideal solution. (It reinforces your point about waiting for a better solution.) Also, thanks for the introduction to PlotRangePadding. – dantopa May 13 '15 at 18:02
• Nice job on six Accepts yesterday. :-) – Mr.Wizard May 14 '15 at 13:42