Last active
June 10, 2019 18:16
-
-
Save justinmeiners/b050fdfb387fd7be1b6fa84f070400fe to your computer and use it in GitHub Desktop.
I explained to a friend how sqrt can be implemented.
This file contains hidden or 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
import math | |
def sqrt(x_0, guess, tol): | |
x = guess | |
while math.fabs(x*x - x_0) > tol: | |
x = (x*x - x_0) / (2.0 * x) | |
return x | |
print(sqrt(2.0, 2.0, 0.0001)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment