Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8072395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:00:26+00:00 2026-06-05T14:00:26+00:00

Possible Duplicate: Matlab gives wrong answer Can anyone explain to me why the following

  • 0

Possible Duplicate:
Matlab gives wrong answer

Can anyone explain to me why the following happens, when I use the 0:.1:1-range function?

>> vecA = 0:.1:1;
>> vecB = [0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1];
>> vecA == vecB

ans =

     1     1     1     0     1     1     1     1     1     1     1

Why is vecA(4) not equal to 0.3? They look quite the same 😉

vecA =

  Columns 1 through 7

         0    0.1000    0.2000    0.3000    0.4000    0.5000    0.6000

  Columns 8 through 11

    0.7000    0.8000    0.9000    1.0000

>> vecB

vecB =

  Columns 1 through 7

         0    0.1000    0.2000    0.3000    0.4000    0.5000    0.6000

  Columns 8 through 11

    0.7000    0.8000    0.9000    1.0000

I think there is a problem with the precision here? Or do I have a problem in my understanding?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T14:00:28+00:00Added an answer on June 5, 2026 at 2:00 pm

    Computers are binary, their native floating-point format can’t exactly store decimal fractions. (You could use a ratio type, or a fixed-point decimal type, but computations using these are far slower.)

    As a consequence, testing floating-point values for equality is practically useless. Check the absolute value of the difference instead.

    You should definitely read What Every Computer Scientist Should Know About Floating Point Arithmetic

    (There are also some simpler explanations, such as http://floating-point-gui.de/ but you should use these to help you understand Goldberg’s paper, not to replace it)


    What you are actually seeing in this case is that 0.2 + 0.1 != 0.3 (the range uses the first version, vecA(3) = vecA(2) + step)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: In MATLAB, can I have a script and a function definition in
Possible Duplicate: How can I index a MATLAB array returned by a function without
Possible Duplicate: How can I generate a list of function dependencies in MATLAB? I
Possible Duplicate: Finding 99% coverage in Matlab How can I compute P10, P50 and
Possible Duplicate: MATLAB date selection popup calendar for gui Does anyone know of a
Possible Duplicate: MATLAB: how to normalize/denormalize a vector to range [-1;1] I'm designing a
Possible Duplicate: Automatically plot different colored lines in MATLAB I have the following data
Possible Duplicate: When do you use the “this” keyword? If I have the following
Possible Duplicate: how to compare array with matlab Here's an example of what I'm
Possible Duplicate: Growable data structure in MATLAB So in my current MATLAB script, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.