Message Boards Message Boards

0
|
4245 Views
|
5 Replies
|
0 Total Likes
View groups...
Share
Share this post:

How to enter high precision numerical constants?

Posted 10 years ago

New to Mathematica (ver 9). Trying to use numerical constants with about 20 decimal places in functions like N, but it keeps converting them to 6 decimal places. I know this has to be an easy thing to do, but cannot find it anywhere in the docs.

POSTED BY: rhutson2
5 Replies
Posted 10 years ago

Thank you, this was exactly what I was looking for. I knew there had to be a simple solution.

POSTED BY: rhutson2

Please reread both my and Marvin's responses carefully.

First: The formatting of output cells is, by default, set so that only 6 digits are displayed for machine precision numbers. The full number of digits are still saved internally--and in fact they are in the cell itself, but only a portion of them are displayed. But you can change the number of digits displayed in the Preferences but going to the Appearance/Numbers/Formatting subtab.

If you do not want to do this you can use FullForm to display the exact number of digits.

Results with a number of digits generated by arbitrary precision arithmetic will display their full set of digits. Eg

N[Pi, 40] + 2 x

The expression that you gave will not give 20 digits of precision as it starts with a machine precision number.

In[28]:= InputForm[N[2 1.23456789, 20]]

Out[28]//InputForm= 2.46913578

You cannot get more precision out than what you put in and may get less, depending on the calculations you do with the numbers.

You can also use NumberForm to show as many digits as you wish, but no more than are actually there. For example this is a machine precision number and so, even though there is a 30 there, only the number of digits that are actually there will be shown:

NumberForm[N[Pi], 30]

You can read more about some of these things here:

http://reference.wolfram.com/language/tutorial/NumericalPrecision.html

POSTED BY: David Reiss
Posted 10 years ago

Here's a simplified example:

N[2*1.23456789, 20]

returns:

2.46914

How do I get it to return more digits?

POSTED BY: rhutson2

Beware of the decimal point! It will kill your high precision.

If you enter

N[E^2,20]

you get 7.3890560989306502272.

But if you enter

N[E^2. ,20] 

You get only 7.38906.

If you need to use fractional amounts rationalize them fiirst

If you want a high precision estimate for 2^2.125. enter

N[2^Rationalize[2.125, 0], 20]

instead of

N[2^2.125, 20]

.The 0 in Rationalize[] makes sure the decimal is rationalized completely, not just substituted by an approximation.

POSTED BY: Marvin Ray Burns

Perhaps an example of what you are doing would help. The default display form for machine precision numbers is 6 places, but the remaining digits are still there. If you are doing a computation with both high precision numbers and machine precision numbers then the result will generally be machine precision unless there are in fact no machine precision numbers... and even then, depending on the calculation, the resulting precision may be less than that of the input numbers. E.g. (note the use of FullForm to show how many digints are actually there.

In[4]:= N[Pi, 30] + N[Pi] // FullForm

Out[4]//FullForm=6.283185307179586`

In spite of using a 30 digit precisin, when combined with a machine precision number the result is Machine precision

Without the FullForm only 6 digits are shown

In[5]:= N[Pi, 30] + N[Pi]

Out[5]= 6.28319
POSTED BY: David Reiss
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract