I get a nice plot, but also a FindRoot::precw: error when I try to plot the results of a function that invokes FindRoot
. I assume the problem originates in how Plot
passes the arguments to the function. Here is a simple notebook that shows this behavior:
eqn = 5*x + 0.1000000000000000000000 + s == 0
(* 0.100000000000000000000 + s + 5 x == 0 *)
Precision[eqn]
(* 21. *)
g[b_] :=
FindRoot[{eqn /. s -> b}, {{x, -13000}},
MaxIterations -> 1000, WorkingPrecision -> 20]
g[-1]
(* {x -> 0.18000000000000000000} *)
g[100]
(* {x -> -20.020000000000000000} *)
Plot[x /. g[s], {s, -10, 10}, WorkingPrecision -> 20]
FindRoot::precw: The precision of the argument function ({-9.89959+5 x==0}) is less than WorkingPrecision (20.`). >>
I tried with and without the WorkingPrecision
option in the plot, and also by wrapping the ranges with a set precision like:
Plot[x/. g[s], {s, SetPrecision[-10, 20], SetPrecision[-10, 20}}]
which looks strange and does not work as well...
To be clear, the generated plot looks nice, but the errors are still annoying.
Plot
is testing the function by plugging in a machine precision value (like-9.99959142857143`
, but also the exact integer10
). $\endgroup$MachinePrecision
is considered less than any arbitrary precision byFindRoot
. You could useQuiet
to ignore the warning. (It's not an error.) Or you could useSetPrecision
insideg
, but I would be less happy with that in some situations. $\endgroup$Quiet
solution, even though I think it is somewhat inconvenient. But I'm relieved that I should not worry too much about this warning. $\endgroup$Quiet@Plot[..]
or evenQuiet[Plot[..], FindRoot::precw]
, which would let real numerical errors be reported. $\endgroup$