Skip to content

Instantly share code, notes, and snippets.

@greezybacon
Created December 10, 2012 16:33
Show Gist options
  • Save greezybacon/4251654 to your computer and use it in GitHub Desktop.
Save greezybacon/4251654 to your computer and use it in GitHub Desktop.
Newton's method for root of 33
def newton_method(x0, fn, dfn):
xn = x0
while True:
xn -= fn(xn) / dfn(xn)
yield xn
root_33 = newton_method(1, lambda x: 33 - x*x, lambda x: -2*x)
for x in range(6):
print(next(root_33))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment