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 6059671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:44:16+00:00 2026-05-23T08:44:16+00:00

There are two similar matlab programs, one iterates 10 times while another iterates 11

  • 0

There are two similar matlab programs, one iterates 10 times while another iterates 11 times.

One:

i = 0;
x = 0.0;
h = 0.1;
while x < 1.0
    i = i + 1;
    x = i * h;
    disp([i,x]);
end

Another:

i = 0;
x = 0.0;
h = 0.1;
while x < 1.0
    i = i + 1;
    x = x + h;
    disp([i,x]);
end

I don’t understand why there is difference between the floating point add operation and the multiple.

  • 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-05-23T08:44:16+00:00Added an answer on May 23, 2026 at 8:44 am

    Compare the output of the following:

    >> fprintf('%0.20f\n', 0.1.*(1:10))
    0.10000000000000001000
    0.20000000000000001000
    0.30000000000000004000
    0.40000000000000002000
    0.50000000000000000000
    0.60000000000000009000
    0.70000000000000007000
    0.80000000000000004000
    0.90000000000000002000
    1.00000000000000000000
    
    >> fprintf('%0.20f\n', cumsum(repmat(0.1,1,10)))
    0.10000000000000001000
    0.20000000000000001000
    0.30000000000000004000
    0.40000000000000002000
    0.50000000000000000000
    0.59999999999999998000
    0.69999999999999996000
    0.79999999999999993000
    0.89999999999999991000
    0.99999999999999989000
    

    Also compare against using MATLAB’s COLON operator:

    >> fprintf('%0.20f\n', 0.1:0.1:1)
    0.10000000000000001000
    0.20000000000000001000
    0.30000000000000004000
    0.40000000000000002000
    0.50000000000000000000
    0.59999999999999998000
    0.69999999999999996000
    0.80000000000000004000
    0.90000000000000002000
    1.00000000000000000000
    

    If you want to see the 64-bit binary representation, use:

    >> format hex
    >> [(0.1:0.1:1)' (0.1.*(1:10))' cumsum(repmat(0.1,10,1))]
       3fb999999999999a   3fb999999999999a   3fb999999999999a
       3fc999999999999a   3fc999999999999a   3fc999999999999a
       3fd3333333333334   3fd3333333333334   3fd3333333333334
       3fd999999999999a   3fd999999999999a   3fd999999999999a
       3fe0000000000000   3fe0000000000000   3fe0000000000000
       3fe3333333333333   3fe3333333333334   3fe3333333333333
       3fe6666666666666   3fe6666666666667   3fe6666666666666
       3fe999999999999a   3fe999999999999a   3fe9999999999999
       3feccccccccccccd   3feccccccccccccd   3feccccccccccccc
       3ff0000000000000   3ff0000000000000   3fefffffffffffff
    

    Some suggested readings (MATLAB related):

    • Cleve’s Corner 1996 article
    • A Glimpse into Floating-Point
      Accuracy
    • How do I determine if the error in
      my answer is the result of round-off
      error or a bug?
    • How does the COLON operator
      work?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are two databases in SQL Server 2005: One called A and another one
There are two UIViews of similar size. UIView one (A) is originally on top
I have two XML files. They are similar, but there are two nodes of
Is there in Ruby some functionality/syntax to compare two floats with delta? Something similar
There are two similar namespaces and assemblies for speech recognition in .NET. I’m trying
When unit testing with JUnit, there are two similar methods, setUp() and setUpBeforeClass() .
In the blackberry JDE 4.7, under the TouchEvent, there are two similar sounding methods:
Seems like there are two products with similar names, but isn't what I expect.
I currently have two tables similar to users and programs that are linked through
i have a simple swing gui where there are two text fields one for

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.