Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: While loop fails
Date: Sun, 23 Oct 2011 19:04:15 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 11
Message-ID: <j81off$mrp$1@newscl01ah.mathworks.com>
References: <j7sh2e$q77$1@newscl01ah.mathworks.com> <j7siql$37t$1@newscl01ah.mathworks.com> <j7t5fi$53$1@newscl01ah.mathworks.com> <j7v0n2$qof$1@speranza.aioe.org> <j81ap4$eqr$1@newscl01ah.mathworks.com> <j81cd0$8uc$1@speranza.aioe.org> <j81n2a$j0b$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-05-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1319396655 23417 172.30.248.37 (23 Oct 2011 19:04:15 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 23 Oct 2011 19:04:15 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:746865

"Julio Gonzalez" <julio@part-time-scientists.com> wrote in message <j81n2a$j0b$1@newscl01ah.mathworks.com>...
> I do appreciate the nature of the problem, , I thought MATLAB will be more intelligent and will deal correctly with the answer. Other programming languages can handle this problem in much better way. I tried the same loop in other programming languages and all of them give the correct answer!
> 
>  Even a simple PERL script can handle the problem... IMHO,  MATLAB could do a better job that PERL.. 
> 
> I understand MATLAB is an engineer tool and it is the engineer that must handle the issue.. 
> .........
- - - - - - - - - -
  Julio, if by "the problem" you mean that your 'to' variable doesn't end up an exact value of 2 after twenty iterations of "to = to+0.1", then you are quite wrong in singling out the matlab language as being responsible.  Any programming system that uses binary floating point numbers will of necessity exhibit a similar behavior.  It is inherent in the nature of binary representation of floating point numbers with a finite number of digits.  You would do well to study up on the subject.  Understanding these principles is fundamental to writing good mathematical programs.

Roger Stafford