Re: Odd problem in Matlab
- From: ellieandrogerxyzzy@xxxxxxxxxxxxxxxxxxxxxx (Roger Stafford)
- Date: Thu, 13 Apr 2006 17:17:46 GMT
In article <e1ls1d$3op$1@xxxxxxxxxxxxx>, kovac <kovac@xxxxxxxxxxxx> wrote:
Hi all,------------------------
I'm pretty new to Matlab so I might be missing something, but here's my
problem. I tried to execute this code:
for (i = 0:0.0001:20),
if (i == 11.8791)
'BLAH'
end
end
The 'BLAH' text will never display. But if I put 11.8792 instead of
11.8791, it will display. Could you tell me why?
Thanks in advance.
Try this:
x = 118791*.0001;
y = 118791/10000;
x==y
and you will notice that they give slightly different results. That is
caused by the fact that the IEEE double precision floating point numbers
used by all our computers are binary numbers and are incapable of
representing either .0001 or 11.8791 exactly. It is not surprising that
the two methods of computing what is supposedly the same number, arrive at
different results.
On your decimal calculater try calculating 3/14 + (3/14 + 15/14) and
(3/14 + 3/14) + 15/14. You may get different answers, in spite of the
associative law of addition, and that would be caused by the calculator's
inability to represent these fractions exactly in decimal. For example,
the fraction 3/14, expressed in decimal terms, is equal to:
0.2142857142857142857142857 ......,
repeated indefinitely, but the calculator has to stop somewhere at an
approximation, just as do IEEE binary floating point numbers.
(Remove "xyzzy" and ".invalid" to send me email.)
Roger Stafford
.
- Prev by Date: reading zipped csv files
- Next by Date: Re: Indexing function handles
- Previous by thread: Re: Odd problem in Matlab
- Next by thread: Question in maov1
- Index(es):
Relevant Pages
|