Re: Adding two numbers of high precision results in a number of low precision??
- To: mathgroup at smc.vnet.net
- Subject: [mg56923] Re: Adding two numbers of high precision results in a number of low precision??
- From: dh <dh at metrohm.ch>
- Date: Tue, 10 May 2005 03:42:31 -0400 (EDT)
- References: <firstname.lastname@example.org>
- Sender: owner-wri-mathgroup at wolfram.com
Hi, here is a simple example that shows that the sum of two numbers can have much slower precision than each number itself: a = SetPrecision[10^250 + 1, 300]; b = SetPrecision[-10^250, 300]; Print["Precision a=", Precision[a]]; Print["Precision b=", Precision[b]]; Print["Precision a+b=", Precision[a + b]]; prints: Precision a= 300. Precision b= 300. Precision a+b= 49.699 Sincerely, Daniel Kees van Schaik wrote: > Hi, > > I have the following question. In a pretty long code (so I won't send > everything) at some point the following loop occurs: > > >>For[i=1,i<=3,i++, >> bTemp[i,0,j]=bTemp[i,0,0]+Q[i,j]; >> Print["Precisie bTemp[",i,",0,0] = ",Precision[bTemp[i,0,0]]]; >> Print["Precisie Q[",i,",",j,"] = ",Precision[Q[i,j]]]; >> Print["Precisie bTemp[",i,",",0,",",j,"] = ",Precision[bTemp[i,0,j]]]; >> ]; (* einde For *) > > > ("Precisie" is Dutch for "precision" ;)), where the j is a loop counter > and the Q[.,.]'s and bTemp[.,0,0]'s are known numbers of a certain > precision. Now two pieces of the output of this piece of code look like > this: > > >>Precisie bTemp[2,0,0] = 397.142 >>Precisie Q[2,1] = 397.172 >>Precisie bTemp[2,0,1] = 395.193 > > > > and > > >>Precisie bTemp[3,0,0] = 389.685 >>Precisie Q[3,1] = 390.729 >>Precisie bTemp[3,0,1] =53.8232 > > > > Now the first one makes sense, but the last one, how is it possible that > if I add two numbers of precision ca. 390 I get something of precision > 53 back? I hope somebody could explain, because there are numerical > problems in my code that mess things up and I'm afraid the stuff above > could have to do with it... > > Thanks in advance & best wishes, Kees van Schaik >