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$>
References: <j7sh2e$q77$> <j7siql$37t$> <j7t5fi$53$> <j7v0n2$qof$> <j81ap4$eqr$> <j81cd0$8uc$> <j81n2a$j0b$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1319396655 23417 (23 Oct 2011 19:04:15 GMT)
NNTP-Posting-Date: Sun, 23 Oct 2011 19:04:15 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: comp.soft-sys.matlab:746865

"Julio Gonzalez" <> wrote in message <j81n2a$j0b$>...
> 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