Re: Understanding N and Precision
- To: mathgroup at smc.vnet.net
- Subject: [mg71197] Re: [mg71147] Understanding N and Precision
- From: "Chris Chiasson" <chris at chiasson.name>
- Date: Fri, 10 Nov 2006 06:37:56 -0500 (EST)
- References: <200611090838.DAA15669@smc.vnet.net>
N[x] is equivalent to N[x,MachinePrecision] not N[x,$MachinePrecision] Mathematica has two kinds of approximate calculations, those where Precision and Accuracy information are variable (and also tracked), and those where it is not variable and not tracked. Please do not conflate this with PrecisionGoal and AccuracyGoal options for certain iterative routines like FindMinimum. N[expr,some number] enables variable accuracy and precision tracking. N[expr,MachinePrecision] or N[expr] just uses fixed precision (hardware based) calculations. note that 9` is a MachinePrecision number 9`20 is a number with a Precision of 20 9 is a number with a Precision of Infinity Finally, it can be very confusing to look at the StandForm Output style because it does not display the ` marks. (the same thing goes for " marks for strings, only it is more complicated) On 11/9/06, Alain Cochard <alain at geophysik.uni-muenchen.de> wrote: > Hi. I would like to understand the following behavior: > > Mathematica 5.2 for Linux > Copyright 1988-2005 Wolfram Research, Inc. > -- Motif graphics initialized -- > > In[1]:= MatrixForm[{{exact1=Cos[3Pi/2+Pi/7], Precision[exact1]}, \ > {exact2=Cos[40139127975 Pi/14], Precision[exact2]}}] > > > Out[1]//MatrixForm= 23 Pi > Cos[-----] > 14 Infinity > > 40139127975 Pi > Cos[--------------] > 14 Infinity > > just checking: > > In[2]:= FullSimplify[exact1-exact2] > > Out[2]= 0 > > In[3]:= MatrixForm[{{float1=N[exact1], Precision[float1]},\ > {float2=N[exact2], Precision[float2]}}] > > > Out[3]//MatrixForm= 0.433884 MachinePrecision > > 0.433883 MachinePrecision > > So the N of supposedly(?) 2 identical numbers is different (although > the precision is indeed the same). That's what I would like to > understand most. > > Also, if I specify the precision for N, it now gives the same. E.g.: > > In[4]:= MatrixForm[{{float1=N[exact1,3], Precision[float1]},\ > {float2=N[exact2,3], Precision[float2]}}] > > > Out[4]//MatrixForm= 0.434 3. > > 0.434 3. > > including the case where the precision asked is MachinePrecision: > > > In[5]:= MatrixForm[{{float1=N[exact1,$MachinePrecision], Precision[float1]},\ > {float2=N[exact2,$MachinePrecision], Precision[float2]}}] > > Out[5]//MatrixForm= 0.4338837391175581 15.9546 > > 0.4338837391175581 15.9546 > > Why in this case does it gives a precision of "15.9546" and not > "MachinePrecision", as above, especially since > > In[6]:= N[$MachinePrecision,Infinity] > > Out[6]:= 15.9546 > > Isn't N[x] equivalent to N[x,$MachinePrecision]? > > Thanks in advance for any tip. > > Alain > > -- http://chris.chiasson.name/
- References:
- Understanding N and Precision
- From: Alain Cochard <alain@geophysik.uni-muenchen.de>
- Understanding N and Precision