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

Contact us at files@mathworks.com