Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!19g2000hsx.googlegroups.com!not-for-mail
From:  enrique.vidal.sanchez@gmail.com
Newsgroups: comp.soft-sys.matlab
Subject: Found bug in SUM?
Date: Tue, 07 Aug 2007 23:57:25 -0700
Organization: http://groups.google.com
Lines: 40
Message-ID: <1186556245.706712.251660@19g2000hsx.googlegroups.com>
NNTP-Posting-Host: 212.247.91.99
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Trace: posting.google.com 1186556245 21935 127.0.0.1 (8 Aug 2007 06:57:25 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Wed, 8 Aug 2007 06:57:25 +0000 (UTC)
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1),gzip(gfe),gzip(gfe)
Complaints-To: groups-abuse@google.com
Injection-Info: 19g2000hsx.googlegroups.com; posting-host=212.247.91.99;
Xref: news.mathworks.com comp.soft-sys.matlab:422869


Hi folks,

I wonder why SUM does not work correctly. Please see the examples
below:

OK:
sum([-0.2:0.1:0.1])
 -0.2000

WRONG:
sum([-0.2:0.1:0.2])
-2.7756e-017

OK:
sum([-0.3:0.1:0.2])
  -0.3000

WRONG:
sum([-0.3:0.1:0.3])
 -5.5511e-017

It doesn't work correctly with vectors which are symmetric around
zero. Is this a know bug (or "feature")?

The Matlab version I am currently using is: 6.5.0.180913a (R13)

It is a very annoying behaviour because there are inbuilt functions in
Matlab like MEAN which call SUM and therefore MEAN in this case
doesn't work as intended either.

Any comment on the above?

Regards,
Enrique

__________
Enrique Vidal Sanchez
Ph.D. in EE. (Automation)
www.vidal.dk