Created
September 23, 2011 20:06
-
-
Save koverholt/1238338 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
from __future__ import division | |
import math | |
def myexp(x): | |
''' myexp(x) will compute e^x for any x by measuring the difference in the last 2 terms of the series. ''' | |
tot = (1 + x) | |
n = 1 | |
while (tot != tot + x): | |
n = n + 1 | |
x = x * (x / n) | |
tot = tot + x | |
return tot | |
x = float(raw_input("Evaluate e at x = ")) | |
e = myexp(x) | |
z = math.exp(x) | |
diff = z - e | |
print "Ans: %0.4f" % e | |
print "Difference: %0.4f" % diff |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment