title: Taylor series of cos x expansion in python
body: <p>I want to calculate the summation of cosx series (while keeping the x in radian). This is the code i created:</p>
  <pre><code>import math
  def cosine(x,n):
      sum = 0
      for i in range(0, n+1):
          sum += ((-1) ** i) * (x**(2*i)/math.factorial(2*i))
      return sum
  </code></pre>
  <p>and I checked it using <code>math.cos()</code> .
  It works just fine when I tried out small numbers:</p>
  <pre><code>print(&quot;Result: &quot;, cosine(25, 1000))
  print(math.cos(25))
  </code></pre>
  <p>the output:</p>
  <blockquote>
  <p><code>Result:  0.991203540954667 </code> <code>0.9912028118634736</code></p>
  </blockquote>
  <p>The number is still similar. But when I tried a bigger number, i.e 40, it just returns a whole different value.</p>
  <blockquote>
  <p><code>Result:  1.2101433786727471</code> <code> -0.6669380616522619</code></p>
  </blockquote>
  <p>Anyone got any idea why this happens?</p>