1
$\begingroup$

I want to do various computations conditional on a given precision for the entire notebook. I use the following code:

Block[{$MaxPrecision = 3},
 SetPrecision[{"various computations"},3]
]

All of the computations are placed in SetPrecision[{...},3]. The output from the above code seems fine but when I use Enter key then the numbers look as if no precision is applied.

Furthermore, how can I override Default Precision with $MaxPrecision=3?

$\endgroup$
10
  • 1
    $\begingroup$ Could you set the precision of your numerical inputs instead? For instance, if you set initialVariable = 1`3 then any calculations that involve that value will automatically keep track of the appropriate precision. $\endgroup$
    – MarcoB
    Commented Nov 29, 2023 at 1:38
  • $\begingroup$ @MarcoB: I have a large matrix mat of numbers. This matrix is used in the computation of variables in the successive steps in the code. How do I set the precision of the matrix mat? $\endgroup$ Commented Nov 29, 2023 at 1:59
  • $\begingroup$ @MarcoB: There must be an easy way to set the precision for the entire notebook. I need to do that because there are many other computations done in the same notebook. $\endgroup$ Commented Nov 29, 2023 at 2:01
  • 4
    $\begingroup$ SetPrecision[mat, 3] would do it. I don't believe there is a "global precision setting" in the sense you intend. Can you explain a bit more why you think you need it? If you want speed, then machine-precision is your best bet anyway, $\endgroup$
    – MarcoB
    Commented Nov 29, 2023 at 2:21
  • 2
    $\begingroup$ It limits the maximum number of digits of precision used in arbitrary-precision numbers, so that may approximate what you want, but there are some significant caveats. For one, machine-precision calculations are not affected, because they do not use the arbitrary-precision machinery. Secondly, and perhaps more importantly, the docs say that "when $MaxPrecision is set, some computations may not get correct results" because a higher precision than requested would be required to obtain the correct result. The latter drawback would be a show-stopper to me. $\endgroup$
    – MarcoB
    Commented Nov 29, 2023 at 18:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.