# Explanation of series for $\sin(x)$ and $\cos(x)$.

Can anyone explain me what is this equation telling us? I need to implement it in my computer program.

I do not need a proof of these, but an explanation of notation used here. $$\sin x = \sum^{\infty}_{n=0} \frac{(-1)^n}{(2n+1)!} x^{2n+1} = x - \frac{x^3}{3!} + \frac{x^5}{5!} - \cdots\quad\text{ for all } x\!$$

AND

$$\cos x = \sum^{\infty}_{n=0} \frac{(-1)^n}{(2n)!} x^{2n} = 1 - \frac{x^2}{2!} + \frac{x^4}{4!} - \cdots\quad\text{ for all } x\!$$

• Do you understand what an infinite series $$\sum_{n=0}^\infty a_n$$ is in general? Commented Feb 23, 2014 at 4:28
• Also, please explain what you consider the definition of the functions $\sin(x)$ and $\cos(x)$. Commented Feb 23, 2014 at 4:29
• All I know about sine and cosine is that they are used to calculate the angles of the two specific given sides and their inverse are used to find the angles. Commented Feb 23, 2014 at 4:30
• It is the Taylor Series expansions for the $\sin x$ and $\cos x$ functions, respectively. Commented Feb 23, 2014 at 4:30
• @SujaanKunalan so what does that mena? Please tell me. :) Commented Feb 23, 2014 at 4:31

First let's deal with the "!" thing. Mathematicians use this to denote the "factorial" of a number $n$, which means $n$ times $n-1$ times $n-2$ ... times 3 times 2 times 1. So, for example, $3! = 3 \times 2 \times 1 = 6$, and $5! = 5 \times 4 \times 3 \times 2 \times 1 = 120$. You can calculate factorials using a recursive function like the following one (written in C#):

public static int Factorial(int n)
{
if (n == 0) return 1;
else return n*Factorial(n-1);
}


Next, the $\sum$ notation. This is just a shorthand way of writing a "summation", which is the addition of a bunch of terms. So, the second equation says that you can calculate $\cos(x)$ by adding up a large number of terms that each have the form $$\frac{(-1)^n}{(2n)!}x^{2n}$$ The C# code to calculate one of these terms (for given $x$ and $n$) is

public static double Term(double x, int n)
{
return Math.Pow(-1, n)*Math.Pow(x, 2*n)/Factorial(2*n);
}


So, the code to add up the first $n$ terms is

public static double CosineSum(double x, int n)
{
double sum = 0;
for (int i = 0 ; i < n ; i++) sum = sum + Term(x,n);
return sum;
}


According to the formula, this CosineSum function should give the same values as the cosine function, if $n$ is large enough. Larger values of $n$ will give better answers.

Of course, all of this is just theory. In practice, if you were writing code in C# (or any other reasonable language) you would just use the built-in cos function.

And, if you really needed to calculate $\cos(x)$ yourself, then there are other approaches that work much better than the series expansion technique we used here. For example, see here.

• what are the other series can you please tell? Commented Feb 23, 2014 at 5:48
• I didn't write what I meant to write. Plese see modified answer. Commented Feb 23, 2014 at 6:14

You can look at is as a definition, or you can look at it as a way of calculating the values for $\sin$ and $\cos$ by computer. Notice that as the series progresses, when $x<1$, higher powers contribute less and less. Thus, were you to write a computer program to calculate the values for $\sin$ and $\cos$, you would only need a finite amount of terms to be accurate to within a desired threshold.

• please explain more.. :/ Commented Feb 23, 2014 at 4:38
• @MohammadAreebSiddiqui - what part do you need explaining? Commented Feb 23, 2014 at 4:40

What you have posted are Taylor Series. They are infinite series that help represent a function like $\sin(x)$ as something that we can actually calculate manually. Click here to read more about taylor series