Skip to content

Instantly share code, notes, and snippets.

@willmurphyscode
Created September 13, 2017 11:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willmurphyscode/465ecd59f0b81737f0f977adf980b424 to your computer and use it in GitHub Desktop.
Save willmurphyscode/465ecd59f0b81737f0f977adf980b424 to your computer and use it in GitHub Desktop.
Calculate the fixed point of cosine in Python
import math
tolerance = 0.00000000000000000001
def tolerance_equals(a, b):
return ((a - b) * (a - b)) < tolerance
def recursive_cosine_fixedpoint(a):
if tolerance_equals(a, math.cos(a)):
return a
return recursive_cosine_fixedpoint(math.cos(a))
print("The fixed point of cosine is {}".format(recursive_cosine_fixedpoint(1)))
# The fixed point of cosine is 0.7390851331706995
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment