SHARE
TWEET

Untitled

a guest Dec 15th, 2013 15 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import math
  2.  
  3. print "COS"
  4. print
  5.        
  6. def mycos(x):
  7.         sum = 0.0
  8.         for k in range(0, 1000):
  9.                 sum += (((-1) ** k) * (x ** (2 * k)))/math.factorial(2 * k)
  10.         return sum
  11.        
  12. for x in range(0, 51, 5):
  13.         print "x = ", x
  14.         print "my = ", mycos(x)
  15.         print "cos = ", math.cos(x)
  16.         print "del = ", math.fabs(math.cos(x) - mycos(x))
  17.         print
  18.        
  19. print "SIN"
  20. print
  21.        
  22. def mysin(x):
  23.         sum = 0.0
  24.         for k in range(0, 1000):
  25.                 sum += (((-1) ** k) * (x ** (2 * k + 1)))/math.factorial(2 * k + 1)
  26.         return sum
  27.        
  28. for x in range(0, 51, 5):
  29.         print "x = ", x
  30.         print "my = ", mysin(x)
  31.         print "sin = ", math.sin(x)
  32.         print "del = ", math.fabs(math.sin(x) - mysin(x))
  33.         print
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top