From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: the sign of the sum of the difference different from the sign of the difference of the sums
Date: Wed, 23 Dec 2009 15:40:25 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 20
Message-ID: <hgtdl9$212$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1261582825 2082 (23 Dec 2009 15:40:25 GMT)
NNTP-Posting-Date: Wed, 23 Dec 2009 15:40:25 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2146203
Xref: comp.soft-sys.matlab:594531

Dear experts,
I'm using matlab 2009b with win xp (coreduo E8500). I should calcolate the difference of the sum of two vectors and I noticed this misbehavior: (you can find the workspace with the two vectors at ):

>> format long
>> sum(lpt -lvt)

ans =


>> sum(lpt)-sum(lvt)

ans =


ok, the numbers are not equal due to the finite precision arithmetic. But, what about the sign? I cannot distinguish which one of the two sums is larger. Is there a way to determine the correct sign of the result, i.e. which one of the sums is larger?
Thanks in advance,