Message Boards Message Boards

0
|
8875 Views
|
8 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Display machine precision numbers for more than 5 significant digits?

Posted 7 years ago

If I want to compute the following

In[6]:= 3^Sqrt[2.0]

Out[6]= 4.7288

The result is given to 5 significant digits, which is quite a small number - a pocket calculator do a lot better. I'm sure the CPU's floating point processor can do a lot better than that. I tried indicating that the 2 was know more precisely than one significant digit, by indicating a number of zeros, but again a result with only 5 significant digits is returned.

In[9]:= 3^Sqrt[2.00000000000]

Out[9]= 4.7288

Obviously I can perform the this particular calculation in arbitrary precision,

In[32]:= N[3^Sqrt[2],20] 

Out[32]= 4.7288043878374149479

but that inconvenient, and slower than desirable. Is there any way to force Mathemaitca to display about 12 digits? A standard Intel CPU should be able to handle that in the vast majority of cases.. I realise that rounding errors can be significant for some calculations, so I might have less than 12 digits, but I'm sure printing to 10 or 12 digits would be a vast improvement, and they would probably all be right.

I tried

In[16]:= N[3^Sqrt[2.000000000000000000],20]

Out[16]= 4.72880438783741495

In[17]:=  Precision[%]

Out[17]= 18.2169

which seems to do the trick, but I wonder if there's a way to display machine precision numbers to a bit more than 5 significant digits. A pocket calculator does better than that.

Dave

POSTED BY: David Kirkby
8 Replies
Posted 7 years ago

Thank you everyone.

POSTED BY: David Kirkby

You have to change correspondent options from Menu:

Edit -> Preferences -> Appearance -> Numbers -> Formatting -> Displayed Precision -> 12
Posted 7 years ago

... or just evaluate

  SetOptions[$FrontEnd, PrintPrecision -> n]

where n is the maximum number of digits used for displaying a machine-precision number.

Another alternative is to always show inexact numbers in FullForm:

 SetOptions[$FrontEnd, NumberMarks -> True]
POSTED BY: Alexey Popkov

Are these options saved or only maintained per session if one uses SetOptions on $FrontEnd?

POSTED BY: Sander Huisman
Posted 7 years ago

When we use SetOptions on $FrontEnd the options are saved in the FrontEnd's init.m file. For changing options for current session only we need to apply it on $FrontEndSession.

POSTED BY: Alexey Popkov

David,

Mathematica does keep all of the precision. You are just seeing how it displays the numbers in its OutpuForm. You should read the documentation about Precision but here is some of it in a nutshell:

ans = 3^Sqrt[2.]

Displays in OuputForm as

4.7288

If you do NumberForm you can see the whole thing (The default of 2.0 is 16 decimal places of precision):

NumberForm[ans,16]

gives

4.728804387837416

You also get all the digits if you do CForm or InputForm, etc.:

ans //CForm

You can set the precision of a number with the prime symbol (`) :

For example:

In[21]:= 3^Sqrt[2`30]

Out[21]= 4.72880438783741494789428334042

This tells mathematica that the 2 is really 2.000... to 30 decimal places.

You can do this as well:

2.35463`15

To mean that the number is 2.3546300000000000000

I hope this helps. As an experiment, take the output of a number from Mathematica and copy and paste it as input -- you will see it add the precision mark and you can see the actual precision of that result -- not what was displayed in the OutputForm.

POSTED BY: Neil Singer

One should note that providing a precision using a prime mark will trigger arbitrary precision numbers as opposed to machine precision numbers. Which has a lot more implications than showing more digits. This is definitely not the problem of the OP. It is just a display issue (if you can call it that) in this case which can be set in the preferences as said by @Henrik Schachner...

POSTED BY: Sander Huisman

Hi David,

this is just a display issue. Consider this:

3^Sqrt[2.0] // FullForm
    (*  Out:   4.728804387837416`  *)

You can adjust the number of digits displayed e.g. in Edit -> Preferences -> Appearance -> Numbers -> Formatting.

... a pocket calculator do a lot better.

You did not believe that really, did you?

Regards -- Henrik

POSTED BY: Henrik Schachner
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