Re: Question about precision.
- To: mathgroup at smc.vnet.net
- Subject: [mg38415] Re: Question about precision.
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Sat, 14 Dec 2002 03:19:50 -0500 (EST)
- References: <atcasb$3m0$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
"Wen-Feng Hsiao" <wfhsiao at libra.seed.net.tw> wrote in message news:atcasb$3m0$1 at smc.vnet.net... > 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] > > Out[28]= > 1.14018 > > In[29]:= > Precision[Sqrt[1.3]] > > Out[29]= > 16 > > In[30]:= > N[Sqrt[1.3], 50] > > Out[30]= > 1.14018 > > In[31]:= > 1.14018*1.14018 > > 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 For Sqrt[1.3] the output is Sqrt[1.3]//InputForm 1.140175425099138 but only the first 6 digits are displayed (controled by the option PrintPrecision - please look up in the Option Inspector). However this is the obtained using machine arithmetic. If we need higher precision we can use one of the following techiques: Add zeros manually Sqrt[1.300000000000000000000000000000] 1.140175425099137979136049025567 Use more cunning Sqrt[1.3`30] 1.140175425099137979136049025567 Change to an exact input N[Sqrt[13/10],30] 1.14017542509913797913604902557 or N[Sqrt[Rationalize[1.3]],30] 1.14017542509913797913604902557 What does NOT work is the following Sqrt[SetPrecision[1.3,30]] 1.140175425099137998610649164903 This is because the zeros are added on in the binary form of 1.3 during evaluation and not, as in the first two ways, in the decimal form, during the pre-evaluation parsing. Check: 1.3`30 1.30000000000000000000000000000 SetPrecision[1.3,30] 1.30000000000000004440892098501 Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay at haystack.demon.co.uk Voice: +44 (0)116 271 4198 Fax: +44 (0)870 164 0565