Re: Odd problem in Matlab



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
.



Relevant Pages

  • Re: Automated information display
    ... The idea would be to have some data, say in CSV format and ... modern computers are capable of programming themselves. ... believe this is immediately obtainable trough programming of weak AI. ... display the data short of solving the entire AI problem. ...
    (comp.ai.philosophy)
  • Re: Data compression in roguelikes
    ... imagine -- they take lots of memory for repeating the same thing over ... Computers have problems with picture analysis. ... It's displaying slow, ... pathfinding algorithms to make your monsters move in them. ...
    (rec.games.roguelike.development)
  • Error Handling
    ... Below is my practice sript to display domain names. ... The computers listed may not acutally be on the network and I thought the ... Dim strComputerRole ... Sub DetectRole ...
    (microsoft.public.scripting.vbscript)
  • Error Handling
    ... Below is my practice sript to display domain names. ... The computers listed may not acutally be on the network and I thought the ... Dim strComputerRole ... Sub DetectRole ...
    (microsoft.public.scripting.wsh)
  • Different Views of OU Dialog Boxes from XP vs Win2000
    ... >Users old machine was Windows 2000 Pro, ... >in Active Directory Users and Computers called Contacts. ... >Tabs in the dialog box.... ... Is there anyway to get XP to display ...
    (microsoft.public.windowsxp.general)