Skip to content

Instantly share code, notes, and snippets.

@JimHaughwout
Created September 6, 2015 20:52
Show Gist options
  • Save JimHaughwout/6d848b543d251f7c96e0 to your computer and use it in GitHub Desktop.
Save JimHaughwout/6d848b543d251f7c96e0 to your computer and use it in GitHub Desktop.
Newton-Raphson for square root
epsilon = 0.00001
y = 25.0
guess = y/2.0
while abs(guess*guess - y) >= epsilon:
guess = guess - (((guess**2) - y)/(2*guess))
print(guess)
print('Square root of ' + str(y) + ' is about ' + str(guess))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment