Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def NonRec(x, eps):
- s=1
- term=1
- i=0
- while (abs(term) > eps):
- term=term*(x/(i+1))
- s+=term
- i+=1
- return s
- import math
- def cosine(x, eps=1e-5):
- res = 1
- i = 1
- x = x * math.pi / 180.
- while True:
- delta = (x**(2*i) / math.factorial(2*i))
- res += (-1)**i * delta
- i += 1
- if delta <= eps:
- return res, i
- In [50]: res, n = cosine(123, eps=1e-6)
- In [51]: print(res, n)
- -0.544639044595552 8
Add Comment
Please, Sign In to add comment