Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: What am I missing here?
Replies: 5   Last Post: Jan 28, 2013 11:03 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Roger Stafford

Posts: 5,815
Registered: 12/7/04
Re: What am I missing here?
Posted: Jan 27, 2013 1:50 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Gautam Sethi <gautamsethi@gmail.com> wrote in message <9fc57693-fa60-4687-a922-e79e26746b69@googlegroups.com>...
> Sure, but why pick on poor .3? Why do I not see the same issue for .2 or .4 or the other numbers? And if this really the root of the issue, shouldn't the operator == be equivalent to <= eps or something similar?
- - - - - - - - -
When you write X = [0 .1 .2 .3 .4] as compared with Y = 0:.1:.4 some of the corresponding elements may come out the same and some different depending on the arithmetic processes involved in the colon operation as opposed to expressing the number directly. Therefore some of them will satisfy the logical equality and some not. However in no case are these four ideal nonzero decimal fractions represented exactly. I suggest you use "format hex" to show the results of both X and Y to see directly those differences and/or similarities.

As to why Mathworks doesn't make an automatic allowance for these small differences in the logical equality operation, it is undoubtedly because the matlab compiler has no way of knowing what kind of error tolerances the user wants to allow and what differences might be significant in the results. Hence they leave such matters to the user to set up.

The important lesson to learn here is that the logical equality operation and other operations that require exactness should not be used on floating point values that are subject to round-off error.

Roger Stafford



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.