MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Question about precision.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg38410] RE: [mg38405] Question about precision.
  • From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
  • Date: Sat, 14 Dec 2002 03:19:35 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Dear Wen-Feng Hsiao,

you liked to learn the difference between the treatment of machine precision
numbers and reals of arbitrary precision in Mathematica.

The definitive Reference is here:
http://documents.wolfram.com/v4/index229.html


>-----Original Message-----
>From: wfhsiao at libra.seed.net.tw [mailto:wfhsiao at libra.seed.net.tw]
To: mathgroup at smc.vnet.net
>Sent: Friday, December 13, 2002 10:19 AM
>To: mathgroup at smc.vnet.net
>Subject: [mg38410] [mg38405] Question about precision.
>
>
>Dear experts,
>
>I try to find the square root of 1.3, but obtain an not so correct
>answer. Could someone point me how to do? My trials are the
>followings.
>
>In[28]:=
>Sqrt[1.3]

	-- you entered a machine-precision number

>
>Out[28]=
>1.14018

	-- output is a machine-precision number, but only 
	   6 decimal positions are displayed

>
>In[29]:=
>Precision[Sqrt[1.3]]
>
>Out[29]=
>16

	-- this is only a formal answer, as precisions of 
	   machine-precision numbers are not really calculated 
	   or adapted.
>
>In[30]:=
>N[Sqrt[1.3], 50]

	-- this doesn't work, since N cannot change a 
         machine-precision number to one of arbitrary precision.
	   The right way to do that is

	Sqrt[SetPrecision[1.3, 50]]
	Out[]= 1.14017542509913799861064916490273263923168523118758

>
>Out[30]=
>1.14018
>
>In[31]:=
>1.14018*1.14018

	-- you should not do such a thing: you typed in what you saw, 
         no wonder what you got!

>
>Out[31]=
>1.30001
>
>The more precise answer should be
>In[32]:=
>1.140175425*1.140175425
>
>Out[32]=
>1.3
>
>Thanks for your help!
>
>Wen-Feng Hsiao
>

Just look at this:

1. Machine Precision
--------------------

In[1]:= $MachinePrecision
Out[1]= 16

In[2]:= Sqrt[1.3]
Out[2]= 1.14018

In[3]:= % // InputForm
Out[3]//InputForm= 1.140175425099138

	-- That is the number (InputForm) you should have typed!
	   (if you like typing)

In[4]:= %*%
Out[4]= 1.3

	-- sufficiently close?

In[5]:= % // InputForm
Out[5]//InputForm= 1.3000000000000003

	-- a small error results, ok, that's machine arithmetic



2. Arbitrary Precision (of same Precision 16)
---------------------------------------------

In[6]:= Sqrt[1.3`16]
Out[6]= 1.1401754250991380

	-- more is displayed, according to precision

In[7]:= % // InputForm
Out[7]//InputForm= 1.140175425099137979136049025540202`16.301

	-- even more positions are delivered her (due to internal  
	   rise of precision, to assure a result of precision 16);
	   of course these extra positions are not significant!

In[8]:= %*%
Out[8]= 1.300000000000000

In[9]:= % // InputForm
Out[9]//InputForm= 1.299999999999999999999999999923524`16

	-- much less error than above with machine-precision.


--
Hartmut Wolf



  • Prev by Date: RE: LabelContourLines bug/feature
  • Next by Date: Re: Re: Why can't Mathematica find this root?
  • Previous by thread: Re: Question about precision.
  • Next by thread: Re: Question about precision.