Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|cite|improve this question

The sequence is alternating and the general term decreases monotonically. So partial sums ending in positive terms will overestimate the value, while partial sums ending in negative terms will be underestimates.

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.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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