0
$\begingroup$

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

$\endgroup$
10
  • $\begingroup$ Do you understand what an infinite series $$\sum_{n=0}^\infty a_n$$ is in general? $\endgroup$ Commented Feb 23, 2014 at 4:28
  • 1
    $\begingroup$ Also, please explain what you consider the definition of the functions $\sin(x)$ and $\cos(x)$. $\endgroup$ Commented Feb 23, 2014 at 4:29
  • $\begingroup$ 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. $\endgroup$ Commented Feb 23, 2014 at 4:30
  • $\begingroup$ It is the Taylor Series expansions for the $\sin x$ and $\cos x$ functions, respectively. $\endgroup$ Commented Feb 23, 2014 at 4:30
  • $\begingroup$ @SujaanKunalan so what does that mena? Please tell me. :) $\endgroup$ Commented Feb 23, 2014 at 4:31

3 Answers 3

2
$\begingroup$

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.

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

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.

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

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

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .