Created
March 15, 2016 14:09
-
-
Save kenchangh/0e397d616602a5282d87 to your computer and use it in GitHub Desktop.
Approximate exponent using continuous fractions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def approximate_exponent(end): | |
denominator = float(end) + 1 | |
for i in xrange(end, 0, -1): | |
denominator = i + i/denominator | |
return 2+1/denominator | |
print approximate_exponent(2) # 2.72727272727 | |
print approximate_exponent(3) # 2.71698113208 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment