8
$\begingroup$

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?

$\endgroup$
8
$\begingroup$

One way is to use ListLinePlot:

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

Mathematica graphics

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]]

Mathematica graphics

$\endgroup$
  • 1
    $\begingroup$ That's a way out, I agree, but suddenly I find myself wondering, why Plot outright refuses to sample the endpoints. $\endgroup$ – LLlAMnYP May 13 '15 at 15:48
  • $\begingroup$ 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. $\endgroup$ – dantopa May 13 '15 at 16:04
  • 1
    $\begingroup$ @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. $\endgroup$ – Michael E2 May 13 '15 at 16:21
  • $\begingroup$ @Michael E2 ParametricPlot is the ideal solution. (It reinforces your point about waiting for a better solution.) Also, thanks for the introduction to PlotRangePadding. $\endgroup$ – dantopa May 13 '15 at 18:02
  • $\begingroup$ Nice job on six Accepts yesterday. :-) $\endgroup$ – Mr.Wizard May 14 '15 at 13:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.