If you Rationalize
your real numbers you will be able to use Mathematica's arbitrary precision engine:
poly2 = Rationalize[poly[z], 0];
Plot[poly2, {z, 0, 1}, WorkingPrecision -> 50]
Arbitrary and machine precision
Mathematica has two kinds of numeric calculations: machine precision, and arbitrary precision. Machine precision is fast but is limited to 53 binary (≈16 decimal) digits(1)(2) and may lose precision during a calculation. Mathematica also does not track the precision of a result.
Numbers entered as 1.234
or 1234`
are taken to be machine precision.
Arbitrary precision is slower, but Mathematica will track the precision of calculations, often using more calculations as necessary to preserve precision, and print the precision of the result.
Exact values such as 1234
and 1/2
can be used in arbitrary precision calculations. Numbers can also be entered with e.g. 1.234`20
specifying 20 digits of precision, and these will automatically use arbitrary precision if all other values are either exact or arbitrary.
Precision can be checked with the function Precision
:
Precision /@ {1.234, 1234`, 1.234`20, 7}
{MachinePrecision, MachinePrecision, 20., ∞ }
Precision can only be preserved if all values in a calculation have at least that precision. Also, arbitrary precision arithmetic may be used with numbers having a precision less than MachinePrecision
-- Mathematica will show the true precision of the result.
Precision[1.234 + 7]
Precision[1.234`20 + 1.234`12]
MachinePrecision
12.301
Precision can be set with SetPrecision
. It is probably better to use this rather than Rationalize
to put numbers into a form that the arbitrary precision engine will use, because the latter will be manufacturing false precision.
Applying this to your problem:
poly3 = SetPrecision[poly[z], 15];
Plot[Evaluate[poly3], {z, 0, 1}, WorkingPrecision -> 50]
During evaluation of In[91]:= Plot::precw: The precision of the
argument function <<>> is less than WorkingPrecision (50.`). >>
This is an important warning because it lets you know that your results may not be valid.
See this tutorial for more information about precision. Take time to understand the difference between Mathematica's meanings of Accuracy
and Precision
.
Recommended reading, a more recent answer from Szabolcs regarding arbitrary precision:
Michael's answer shows the folly of simply doing a Rationalize
as I did at the start of this answer. Since questions like this come up often it would be good to have a general solution that is easily applied. I propose this rule using his formula:
machineToInterval =
c_Real?MachineNumberQ :>
Interval[ {1 - 2^-54, 1 + 2^-54} SetPrecision[c, ∞] ];
This converts any machine numbers into explicit Interval
form.
To extract an ordered pair of values from a numeric Interval
we merely need First
.
poly3 = poly[z] /. machineToInterval;
Plot[{First @ poly3, poly[z]}, {z, 0, 1}
, WorkingPrecision -> 50
, PlotStyle -> {{Thick, Red}, ColorData[97][1]}
]