Search All of the Math Forum:

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

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

 Messages: [ Previous | Next ]
 Roger Stafford Posts: 5,929 Registered: 12/7/04
Re: What am I missing here?
Posted: Jan 27, 2013 1:50 AM

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

Date Subject Author
1/26/13 gautamsethi@gmail.com
1/26/13 gautamsethi@gmail.com
1/26/13 Roger Stafford
1/26/13 gautamsethi@gmail.com
1/27/13 Roger Stafford
1/28/13 Steven Lord