Path: news.mathworks.com!not-for-mail
From: "Steve Amphlett" <Firstname.Lastname@Where-I-Work.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: What happened to so simple Matlab code?
Date: Wed, 21 Nov 2007 09:25:03 +0000 (UTC)
Organization: Ricardo UK Ltd
Lines: 24
Message-ID: <fi0thf$9p1$1@fred.mathworks.com>
References: <8220611.1195636303283.JavaMail.jakarta@nitrogen.mathforum.org>
Reply-To: "Steve Amphlett" <Firstname.Lastname@Where-I-Work.com>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1195637103 10017 172.30.248.37 (21 Nov 2007 09:25:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 21 Nov 2007 09:25:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 43398
Xref: news.mathworks.com comp.soft-sys.matlab:438642



crammer008 <luochao2000@hotmail.com> wrote in message 
<8220611.1195636303283.JavaMail.jakarta@nitrogen.mathforum.o
rg>...
> Dear all, I have the following code and the corresponding 
results:
> +++++++++++++++++++++++++++++++
> >> aa = 0.005:0.01:0.025
> aa =
>     0.0050    0.0150    0.0250
> >> daa = diff(aa)
> daa =
>     0.0100    0.0100
> >> daa(1)-daa(2)
> ans =
>   1.7347e-018
> ++++++++++++++++++++++++++++++++++
> Obviously, we should have daa(1)-daa(2) = 0. Who can tell 
me why Matlab can not give the correct result? Thanks!


Check out the FAQ.

http://matlabwiki.mathworks.com/MATLAB_FAQ#Why_is_0.3-0.2-
0.1_not_equal_to_zero_.28or_similar.29.3F