I'd like to understand why one of these inputs gives me an error and the other doesn't:
s1 =
NDSolve[
{x'[t] == x[t], x[0] == SetPrecision[1., 10]},
{x}, {t, 0, 1},
WorkingPrecision -> $MachinePrecision
][[1]]
NDSolve::precw: The precision of the differential equation ({{(x^[Prime])[t]==x[t],x[0]==1.000000000},{},{},{},{}}) is less than WorkingPrecision (15.954589770191003`). >>
(* Out: {x -> InterpolatingFunction[{{0, 1.000000000000000}}, <>]} *)
versus
s2 =
NDSolve[
{x'[t] == x[t], x[0] == SetPrecision[1., 10]},
{x}, {t, 0, 1},
WorkingPrecision -> MachinePrecision
][[1]]
(* Out: {x -> InterpolatingFunction[{{0., 1.}}, <>]} *)
Notice that the only difference is the fact that $MachinePrecision
got changed to MachinePrecision
. Also, oddly enough, the resulting answers are not identical:
x1[t_] = Evaluate[x[t] /. s1];
x2[t_] = Evaluate[x[t] /. s2];
Plot[x1[t] - x2[t], {t, 0, 1}]
$MachinePrecision
in the current version of Mathematica forces the (admittedly counterintuitive in this case) use of the arbitrary-precision numerics.MachinePrecision
is the right setting to use if you want to stay within machine precision computations, but you do run the risk of hitting instabilities if you are the unlucky sort. $\endgroup$$MachinePrecision
is the number of digits of precision that is roughly equivalent to running a native machine-precision calculation on your system. You can evaluate it, and it will return a real number, on my system for instance ca. 15.9. Now think of it this way:WorkingPrecision -> someNumber
forces the use of the arbitrary precision engine, withsomeNumber
digits of precision. ... $\endgroup$WorkingPrecision -> $MachinePrecision
triggers the use of the arbitrary precision system, with a number of digits of precision that mimics the native machine's precision, but now with error tracking thanks to the arbitrary precision engine. A comparative example can be found in the "Possible Issues" section of the docs on$MachinePrecision
. $\endgroup$