# Good practice about numerical precision

In one of my calculations, I get -1.11022*10^-16 as one of my eigenvalues for a matrix. It's essentially zero and I suppose I could use SetPrecision to make it zero but I wonder what's a good practice here? Should I maybe include something at the beginning of the code to specify precision for everything? Or do I just set arbitrary precision when I feel my expression is not simplified enough?

I'm pretty new to Mathematica.

As others have commented, after trying in different calculations, I think use \Chop after each calculation is the best and safest way.One can also explicitly specify the digits to keep.

• You could apply Chop. – Chris K Jan 9 '19 at 4:31
• I do not believe that you really want to ess with precision here. You just want to push values close to 0. to 0.. This can be done by Threshold and by specifying a suitable tolerance as second argument. – Henrik Schumacher Jan 9 '19 at 8:17
• Thank you guys. Is there a way to Chop/Threshold the whole notebook? Or I just apply these functions after whatever output I get? – Histoscienology Jan 11 '19 at 17:07

Mathematica has three different types of numbers.

Exact numbers, e.g.

5, Sqrt[2], 4/3, ...


Machine precision numbers

1.23, 5., .4566, ...


And numbers with a set precision

5.16, 1.23455, ...


You can tell what kind of number something is by applying Precision to it.

If all your input number have an set precision, then the output of you eigenvalue computation should also have a finite precision attached to it. This will allow you to distinguish between an eigenvalue that is really small an one that is consistent with zero within the expected accuracy.

• Thanks. So you mean I should set every input with a precision as " `some number?" And how can Sqrt[2] and 4/3 be exact?? – Histoscienology Jan 11 '19 at 4:22