1
$\begingroup$

I'm using Taylor series to estimate trigonometric functions. So I need to know exactly how many iterations of Taylor series (say for sine) are needed for n decimal digits precision?
(I'm writing a calculator program)
Thanks in advance

$\endgroup$
  • 1
    $\begingroup$ That depends on the function. Look into the error. $\endgroup$ – Git Gud Oct 10 '13 at 13:11
  • $\begingroup$ Can you explain a bit? Particularly for sine function. (Simple please, I'm a first year student at university studying computer science) $\endgroup$ – SepehrM Oct 10 '13 at 13:16
  • $\begingroup$ I don't know how to give you a simple answer, to be honest. Hopefully someone better versed at this can find a way to explain it to you. $\endgroup$ – Git Gud Oct 10 '13 at 13:18
  • $\begingroup$ It also very dependent on the computing environment. Although $\sin(x)$ has an alternating Taylor series which is theroretically convergent for all real $x$, you will actually have numerical convergence only for small absolute values, for larger $x$ there must be cancellation, eg. for $x=42$ the largest term is about $10^{17}$, but $|\sin(x)|\le 1$! Therefore you will not get any correct digit with IEEE double! $\endgroup$ – gammatester Oct 10 '13 at 13:41
  • $\begingroup$ @gammatester, What's best algorithm for estimating sine? $\endgroup$ – SepehrM Oct 10 '13 at 13:45
1
$\begingroup$

The answer depends heavily on the distance between the point where you are taking the Taylor series (presumably at$~0$) and the value$~x$ for which you want to compute $\sin x$. The larger $|x|$, the worse the performance of the Taylor series, and the more terms are needed for a reasonable approximation. You may of course use the periodicity of the sine function to limit $|x|$ (supposing $x$ is real) before invoking your approximation.

$\endgroup$
  • $\begingroup$ So there is no formula for number of iteration needed knowing x and the desired precision? $\endgroup$ – SepehrM Oct 10 '13 at 13:19
  • 1
    $\begingroup$ You can work out a formula for the number of iterations needed given the coefficients of the Taylor series itself, the value of $|x|$, and the desired precision. In the practical range of application, evaluated terms of the Taylor series tend to $0$ at least as fast as a geometric progression, which means that the error is proportional to the first term not taken into account. If the geometric progression converges rapidly (ratio much less than$~1$), the size of that first omitted term itself is a fair estimate. $\endgroup$ – Marc van Leeuwen Oct 10 '13 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.