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

1.9k Views Asked by At

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\! $$

3

There are 3 best solutions below

2
On BEST ANSWER

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.

2
On

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.

0
On

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