Last active
August 29, 2015 14:23
-
-
Save daedalus/ed4a833abf27741445b8 to your computer and use it in GitHub Desktop.
sqrt2aprox
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
# given the x**2-2=0 condition we bruteforce an aproximation to sqrt(2) | |
def sqrt2test(): | |
x = 2 | |
error = 1 | |
step = 0.5 | |
lower_error = 1 | |
i = 0 | |
while (error != 0): | |
i = i + 1 | |
error = (x**2-2) | |
x = x - (error * step) | |
if error < lower_error: | |
lower_error = error | |
print "Count: %d, Aprox: %s, Error: %s, LowerError: %s" % (i,x,error,lower_error) | |
sqrt2test() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment