This
F[p_]:=(Print[{p,Precision[p]}];If[p==0,1,FindRoot[Erf[Sqrt[p*r]]==((2/Sqrt[\[Pi]])*Sqrt[p]),{r,2},WorkingPrecision->100,PrecisionGoal->16][[1]][[2]]]);
Plot[F[p],{p,0,\[Pi]/4},PlotRange->{0,30},PlotPoints->5000]
shows that Plot
is using MachinePrecision
for each step of the calculation and passing those values to F[p]
, after recognizing that 0
and Pi
are exact. That does not seem surprising. You are asking FindRoot
to work with 100 digits of precision in the calculations it does and it can't produce that precision given the less precise MachinePrecision
value for p
. I believe that is the reason for the warning.
So I will try to sidestep that warning with
F[p_]:=(Print[{p,Precision[p]}];If[p==0,1,FindRoot[Erf[Sqrt[p*r]]==((2/Sqrt[\[Pi]])*Sqrt[p]),{r,2},WorkingPrecision->100,PrecisionGoal->16][[1]][[2]]]);
Plot[F[p],{p,0,\[Pi]/4},PlotRange->{0,30},PlotPoints->5000,WorkingPrecision->100]
which instructs Plot
to use 100 digit math. That shows that Plot
has made all the subsequent calculations done with 100 digits and thus pass 100 digit precision arguments to F[p]
, but that first step remains MachinePrecision
which still triggers that warning. I don't have an explanation for that.
The warning remains even if I change your PrecisionGoal
to 32 or 100 or any other value.
I suppose you could do this
F[p_]:=(q=SetPrecision[p,100];
Print[{q,Precision[q]}];
If[q==0,1,FindRoot[Erf[Sqrt[q*r]]==((2/Sqrt[\[Pi]])*Sqrt[q]),{r,2},WorkingPrecision->100,PrecisionGoal->16][[1]][[2]]]);
Plot[F[p],{p,0,\[Pi]/4},PlotRange->{0,30},PlotPoints->5000,WorkingPrecision->100]
but that worries me. Maybe there is a better way if the precision is essential for the FindRoot