Thread Subject: Logical error

Subject: Logical error

From: Andrew

Date: 22 Oct, 2009 14:50:22

Message: 1 of 3

I am getting a logical error with the following code which I don't understand and would appreciate any help figuring out:

>> n=0.6:0.05:2.0;
>> any(n==1.2)

ans =

     0

>> any(n==1.0)

ans =

     1

I can check all of the values in n and only the value of 1.2 returns false. I would appreciate any help figuring this one out. Thanks.

Subject: Logical error

From: Matt

Date: 22 Oct, 2009 15:41:21

Message: 2 of 3

"Andrew " <apkelley@princeton.edu> wrote in message <hbprfe$lvf$1@fred.mathworks.com>...
> I am getting a logical error with the following code which I don't understand and would appreciate any help figuring out:
>
> >> n=0.6:0.05:2.0;
> >> any(n==1.2)
>
> ans =
>
> 0
>
> >> any(n==1.0)
>
> ans =
>
> 1
>
> I can check all of the values in n and only the value of 1.2 returns false. I would appreciate any help figuring this one out. Thanks.

FAQ. The values of of n are not exact, because there are floating point errors in generating them. It's pure luck that any of them return the expected result.

Subject: Logical error

From: Matt Fig

Date: 22 Oct, 2009 16:04:20

Message: 3 of 3

http://matlabwiki.mathworks.com/MATLAB_FAQ#Why_is_0.3-0.2-0.1_not_equal_to_zero_.28or_similar.29.3F

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
faq_6point1 Matt Fig 22 Oct, 2009 12:08:33
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com