Re: Re: Re: Accuracy and Precision

*To*: mathgroup at smc.vnet.net*Subject*: [mg37097] Re: [mg37076] Re: [mg37058] Re: Accuracy and Precision*From*: David Withoff <withoff at wolfram.com>*Date*: Wed, 9 Oct 2002 05:25:52 -0400 (EDT)*Sender*: owner-wri-mathgroup at wolfram.com

> > > > In[24]:= > > > > f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - > > > > 121*b^4 - 2) + 5.5*b^8 + a/(2*b), 100]; > > > > a=SetPrecision[77617.,100]; b = SetPrecision[33096.,100]; > > > > > > > > In[26]:= > > > > {f, Precision[f]} > > > > > > > Out[26]= > > > {-0.82739605994682136814116509547981629199903311578438481991\ > > > 781484167246798617832`61.2597, 61} > > > > > > Congratulations! You just requested accuracy of > > 100 for f and got 61 ( > > > to convince yourself add Accuracy[f] to In[26]). There is no request in that example for an accuracy of 100 in the result. The only request is for an accuracy of 100 in the input. > > In[26]:= f = SetAccuracy[333.75*b^6 + > > a^2*(11*a^2*b^2 - b^6 - > > 121*b^4 - 2) + 5.5*b^8 + a/(2*b), 100]; > > > > In[27]:= Accuracy[f] > > Out[27]= 100. > > > > Now we assign values to some indeterminants in f. > > > > In[28]:= a = SetPrecision[77617.,100]; b = SetPrecision[33096.,100]; > > > > In[29]:= {f, Precision[f], Accuracy[f]} > > Out[29]= > > {-0.8273960599468213681411650954798162919990331157843848199178148, > > 61.2599, 61.3422} > > > > The precision and accuracy has dropped. This is all > > according to > > standard numerical analysis regarding cancellation > > error. You'll find it in any textbook on the topic. > > > > Assume that I want accuracy and precision of 100 for > f. You advice me to make experiments to find out, what > should be the initial precision and accuracy of a and > b to reach the requested accuracy and precision for f. > Notice, that you cannot just repeat I[26], we saw > already what happens. I have to re-type I[24], I[25], > I[26], I[27], I[28], and I[29] as many times as needed > to get f with accuracy and precision 100. > > Dan, you simply advocate to do MANUAL WORK that should > be done by machine. You do not have to do any of this manually. The machine (Mathematica) will do all of this, usually using built-in functions. The N function, for example, will automatically adjust the working precision to give you a precision that you request, provided that doing so doesn't involve making up arbitrary digits. The example above starts out with machine numbers (333.75, 5.5, etc.), uses SetPrecision and SetAccuracy to make up arbitrary digits to pad those numbers out to some specified number of digits, and then does some simple arithmetic. If the goal is to get some specified number of digits in the result, and it is ok to make up arbitrary digits like this to achieve that goal, then the only manual work required to achive that goal is to apply SetAccuracy or SetPrecision to the result, to tell the computer that that is what you want. > Let's suppose that in the above example I just want 60 > digits not 61. Precisely, I want 60 digits and nothing > or zeros afterwards. Let's see if I could use > SetAccuracy. > > In[30]:= SetAccuracy[%, 60] > > Out[30]= -0.82739605994682136814116509547981629199903311578438481991781 > > In[31]:= % // FullForm > > Out[30]//FullForm= > -0.827396059946821368141165095479816291999033115784384819917814841672467988`\ > 59.9177 > > Oops, it did not work (as expected). If you could explain what you were expecting I am sure there are many contributors to this group who could explain to you why it did not do that. > Let's highlight > with mouse the expression in Out[30] and copy to a new > cell. Oops, we got > -0.827396059946821368141165095479816291999033115784384819917814841672467988`\ > 59.9177 again. Let's change Out[30] to a text cell and then copy. > > In[31]:= -0.82739605994682136814116509547981629199903311578438481991781 > > Out[31]= -0.82739605994682136814116509547981629199903311578438481991781 > > Success? Not so fast. If you could describe what you were trying to achieve with all of that copying and pasting and such I am again sure that there are many contributors to this group who could describe how to do it. It is very unlikely that the process will involve any copying and pasting or detours through text cells. > In[32]:= > % // FullForm > > Out[32]//FullForm= > -0.827396059946821368141165095479816291999033115784384819917809999999999998635\ > 08`59.2041 > > Dan, is there any simple way to get what I want? Probably the answer is yes, but you will have to describe more clearly what you want. > As I repeated already number of times, at this stage > of the development of computer technology, software > should do it for me (!). If what you want to do is get a certain number of digits in the result, and it is ok to make up arbitrary digits as in the examples above, then you can do that by simply applying SetPrecision or SetAccuracy to the result. If you want the computer to automatically adjust the working precision to give a certain precision in the result, you can do that using N. If you want something else, and you can describe what that is, then probably someone can describe how to get Mathematica to do that for you. Dave Withoff Wolfram Research

**Re: Operating on every k-th element of list?**

**RE: Re: Re: Accuracy and Precision**

**Re: Re: Accuracy and Precision**

**RE: Re: Re: Accuracy and Precision**