Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.



Re: What am I missing here?
Posted:
Jan 27, 2013 1:50 AM


Gautam Sethi <gautamsethi@gmail.com> wrote in message <9fc57693fa604687a922e79e26746b69@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 roundoff error.
Roger Stafford



