Skip to content

Instantly share code, notes, and snippets.

@certik certik/gist:996210
Created May 27, 2011

Embed
What would you like to do?
sqrt(x) using Newton method
def sqrt(x):
eps = 1e-10
x = float(x)
r = x/2
residual = r**2 - x
while abs(residual) > eps:
r -= residual/(2*r)
residual = r**2 - x
return r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.