Path: news.mathworks.com!not-for-mail
From: "Julio Gonzalez" <julio@part-time-scientists.com>
Newsgroups: comp.soft-sys.matlab
Subject: While loop fails
Date: Fri, 21 Oct 2011 19:27:10 +0000 (UTC)
Organization: Part Time Scientists
Lines: 19
Message-ID: <j7sh2e$q77$1@newscl01ah.mathworks.com>
Reply-To: "Julio Gonzalez" <julio@part-time-scientists.com>
NNTP-Posting-Host: www-06-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1319225230 26855 172.30.248.38 (21 Oct 2011 19:27:10 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 21 Oct 2011 19:27:10 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1429082
Xref: news.mathworks.com comp.soft-sys.matlab:746724

I am trying to get a while loop to work. I have an integer T, that I converted to double using the function double. But when I print the value of double T, it shows T as an integer and not as a double. Therefore my loop fails. This is the code:

Ti=2
T = double(T);
to= 0.0000;

while (T<=to) 
    to = to+0.1;
    %some code here.....
end

the loop end at to=2.0000; it should end at 2.1000

Is there any other way to fix this problems besides T=2*(1+eps)?

Regards

Julio
University of Liverpool