Results 1 to 4 of 4

Math Help - Matlab question! Help! Infinite loop.

  1. #1
    Newbie
    Joined
    Jun 2010
    Posts
    9

    Matlab question! Help! Infinite loop.

    I can't seem to figure out this question:

    N = 1;
    while N < N + 1
    N = N*10
    end

    All variables are IEEE double precision. Will the code above result in an infinite loop?

    I believe this will be a infinite loop because the value N is always going to be compared to a value 1 unit greater than itself, but what does that its double precision have to do with anything?

    Thanks,
    Naruto
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Member
    Joined
    Nov 2009
    Posts
    130
    And why you did that?

    What is the goal of this loop??

    Yes, it is infinite loop because the condition N < N+1 is always satisfied.

    Double precision is common for decimal point numbers, and double precision means that there the numbers are represented by 64 bits.

    Regards.
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Jun 2010
    Posts
    9
    There is no goal. It was simply a question on a practice exam.

    BTW thank you for your response.
    Follow Math Help Forum on Facebook and Google+

  4. #4
    MHF Contributor undefined's Avatar
    Joined
    Mar 2010
    From
    Chicago
    Posts
    2,340
    Awards
    1
    Quote Originally Posted by naruto View Post
    There is no goal. It was simply a question on a practice exam.

    BTW thank you for your response.
    Regarding IEEE double precision: I'm guessing MATLAB uses arbitrary precision integers, meaning if you need a very large integer, there will be memory allocated accordingly; but in other languages, if for example you use signed 32-bit integers, then it's possible for N < N+1 to fail. So in Java the maximum value for a 32-bit integer is 2^31-1 = 2,147,483,647, and if you add 1 to it you get -2^32 = -2,147,483,648. This is called integer overflow.

    Anyway that's my guess as to why they put IEEE double precision in there, because I don't think N < N+1 can fail in that instance, in any language.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Matlab while loop, Please help!
    Posted in the Math Software Forum
    Replies: 1
    Last Post: April 23rd 2010, 02:14 AM
  2. help with MATLAB questdlg loop
    Posted in the Math Software Forum
    Replies: 1
    Last Post: March 7th 2010, 10:23 AM
  3. Creating a loop in Matlab help
    Posted in the Math Software Forum
    Replies: 1
    Last Post: February 11th 2010, 04:06 AM
  4. Matlab While Loop Help
    Posted in the Math Software Forum
    Replies: 1
    Last Post: March 8th 2009, 08:50 PM
  5. Matlab loop help
    Posted in the Math Software Forum
    Replies: 2
    Last Post: July 20th 2008, 11:47 AM

Search Tags


/mathhelpforum @mathhelpforum