Like Tree2Likes
  • 1 Post By laserlight
  • 1 Post By grumpy

iteration bound determination

This is a discussion on iteration bound determination within the C Programming forums, part of the General Programming Boards category; suppose I want to find the value of e ,e^x or sin(x) or any such function in general ,through their ...

  1. #1
    Registered User
    Join Date
    Aug 2012
    Posts
    73

    iteration bound determination

    suppose I want to find the value of e ,e^x or sin(x) or any such function in general ,through their infinite series (maclaurin or taylor) how many iteration should I have to make to get the result correct uptu 'n' decimal places?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,159
    You could keep on iterating until the absolute difference between the result of the current and previous iterations is less than some pre-determined value, e.g., 1/10^n, where ^ denotes exponentiation.
    progmateur likes this.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Aug 2012
    Posts
    73
    Can you please ellaborate?

    You mean when correct to n decimal digit is given I have to compare the results of previous iterations from.000000000.....1 (n-1 o's ) ...? can you take the trouble of explaining it for eXp(x) please

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    6,531
    That question has no general answer, other than "it depends". Actually, the question is virtually meaningless.

    For calculation of e, one possible stopping criterion would be something like one of the terms in the series being less than 0.5*10^-n.

    For other functions, f(x), the convergence condition would depend on both the function and the value of x. Calculating e^(0.5) would converge a lot faster than the calculation of e^100.

    The number of iterations needed also is affected by whether the function converges monotonically (e.g. approaches the actual value consistently from above or below), oscillates above and below the result (due to changing sign of terms in the series), and whether the series behaves divergently at first, before starting to converge.

    Technically, a power series expansion for a function f(x) is always convergent - eventually - but for some values of x can be divergent for a while before becoming convergent (i.e. the number of iterations to get within a specified accuracy can be quite large).
    progmateur likes this.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy in reply to you, it is likely you deserve it. Suck it up, sunshine, and read this, this, and this before posting again.

  5. #5
    Registered User
    Join Date
    Aug 2012
    Posts
    73
    can it be determined from the error that arise from the maclaurin series in infinite form?

  6. #6
    Registered User
    Join Date
    Aug 2012
    Posts
    73
    why is absolute error inequality taken?

  7. #7
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,832
    'absolute' is only taken to save you from doing two tests - one where the new result is above, one where it is below the previous result.

    If you can define what the nth decimal pace is, for example, 0.000x would be an error of 0.0001 regardless of magnitude of the integer number part, then all you have to do is find out if the new result differs by less than that amount.
    Of course several more terms could be calculated so that any rounding accumulation may still affect that digit. I really don't know how to guarantee that no matter how many more terms are calculated that a certain digit will not change due to rounding.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Prime number determination?
    By frankp124 in forum C Programming
    Replies: 3
    Last Post: 10-17-2012, 07:22 PM
  2. Algorithm for constant signal determination
    By anthei in forum General AI Programming
    Replies: 4
    Last Post: 12-02-2010, 03:55 AM
  3. Matrix Determination calculation
    By disruptivetech in forum C Programming
    Replies: 1
    Last Post: 04-17-2008, 07:46 AM
  4. CPU-bound and I/O bound
    By jacktibet in forum Linux Programming
    Replies: 3
    Last Post: 11-11-2003, 12:16 PM
  5. Path Determination
    By AMAN GABA in forum Windows Programming
    Replies: 5
    Last Post: 10-08-2001, 03:26 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21