Thread: iteration bound determination

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

    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
    28,413
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Aug 2012
    Posts
    77
    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,815
    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).
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  5. #5
    Registered User
    Join Date
    Aug 2012
    Posts
    77
    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
    77
    why is absolute error inequality taken?

  7. #7
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    '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, 06: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, 06: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, 02:26 AM