# Calculating Trigonometric Ratios for Sine and Cosine

The Sine, Cosine of x can be computed as follows:

$$\sin(x) = x - \dfrac {x^3}{3!} + \dfrac {x^5}{5!} - \dfrac {x^7}{7!} + \dfrac {x^9}{9!} …$$

$$\cos(x) = 1 - \dfrac {x^2}{2!} + \dfrac {x^4}{4!} - \dfrac {x^6}{6!} + \dfrac {x^8}{8!} …$$

How to compute the Sine and Cosine for given values of $x$ (where $x$ is in radians) using the above series upto 5 terms in as less characters of program?

-

So if $|x| \le 1$, then using $x - x^3/3! + x^5/5! - x^7/7!$ for $\sin$ will have an error less than $\frac{1}{9!} < 10^{-5}$. Similarly, if we use terms of $\cos$ to the $x^8/8!$ term, we get an error less than $\frac{1}{10!} < 10^{-6}$.
However, if $1 < |x| \le \pi$, then we need more terms to achieve this accuracy. For $|x|$ close to $\pi$, you will need to use terms until $x^{12}/{12!}$ for $\cos$ and $x^{13}/13!$ for sine to achieve an accuracy of $5$ decimal places.