Re: Adding two numbers of high precision results in a number of low precision??David Bailey,http://www.dbaileyconsultancy.co.uk
- To: mathgroup at smc.vnet.net
- Subject: [mg56970] Re: Adding two numbers of high precision results in a number of low precision??David Bailey,http://www.dbaileyconsultancy.co.uk
- From: David Bailey <dave at Remove_Thisdbailey.co.uk>
- Date: Wed, 11 May 2005 05:24:59 -0400 (EDT)
- References: <d5mv2v$dv0$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
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
>
If you subtract two numbers that are almost equal, you end up with
something of lower precision. In your case I imagine you are adding two
numbers that are almost equal, but of opposite sign.
David Bailey
http://www.dbaileyconsultancy.co.uk