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?
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 ...
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?
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.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
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
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).
can it be determined from the error that arise from the maclaurin series in infinite form?
why is absolute error inequality taken?
'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.