Legacy Documentation

Mathematica® Teacher's Edition (2002)

This is documentation for an obsolete product.
Current products and services
 Documentation /  Mathematica Teacher's Edition /  The Teacher's Book /  Basic Calculations /  Real and Complex Numbers /

4.7 Numerical Precision

As discussed in Section 2.2, Mathematica TE can handle approximate real numbers with any number of digits. In general, the precision of an approximate real number is the number of decimal digits in it that are treated as significant for computations. The accuracy of an approximate real number is the number of decimal digits that appear to the right of the decimal point. Precision is thus a measure of the relative error in a number, while accuracy is a measure of absolute error.

Precision and accuracy of real numbers.

Here is an approximate real number.

In[1]:= xacc = 431.123145333555141444

Out[1]=

This gives the total number of digits entered to specify the real number.

In[2]:= Precision[xacc]

Out[2]=

This gives the number of digits that appear to the right of the decimal point.

In[3]:= Accuracy[xacc]

Out[3]=

When you use N[expr, n], Mathematica TE evaluates the expression expr starting with numbers that have n digits of precision. As discussed below, however, the fact that such numbers are used does not necessarily mean that the results you get will have n digits of precision. In most cases, your results will have at least slightly fewer digits of precision.

This evaluates Pi^25 using numbers with 30 digits of precision.

In[4]:= N[Pi^25, 30]

Out[4]=

The result has 29 digits of precision.

In[5]:= Precision[%]

Out[5]=

In doing numerical computations, it is inevitable that you will sometimes end up with results that are less precise than you want. Particularly when you get numerical results that are very close to zero, you may well want to assume that the results should be exactly zero. The function Chop allows you to replace approximate real numbers that are close to zero by the exact integer 0.

Removing numbers close to zero.

Here is the numerical value of the square root of I in the first quadrant.

In[6]:= N[ Sqrt[I] ]

Out[6]=

This computation gives a small imaginary part.

In[7]:= % ^ 2

Out[7]=

You can get rid of the imaginary part using Chop.

In[8]:= Chop[%]

Out[8]=

Other Mathematica functions related to numerical precision. (See Section 3.2.)