Skip to content

Instantly share code, notes, and snippets.

@gibsramen
Created March 7, 2017 19:07
Show Gist options
  • Save gibsramen/8ad4af5a1f208fd9f669cf4178e419fb to your computer and use it in GitHub Desktop.
Save gibsramen/8ad4af5a1f208fd9f669cf4178e419fb to your computer and use it in GitHub Desktop.
Newton-Raphson Code
def newton_method(f, df, x0, err, W):
"""
Estimate p using Newton-Raphson method.
Output: root approximation given error criterion (err)
"""
delta = err+1
x = x0
while delta > err:
x1 = x - f(x, W) / df(x)
delta = abs(x1 - x)
x = x1
return x
def newton_method2(f, df, x0, err, W, S, T, M, p):
"""
Estimate X using Newton-Raphson method.
Output: root approximation given error criterion (err)
"""
delta = err+1
x = x0
while delta > err:
x1 = x - f(S, x, p, W, M, T) / df(x, p, W, M, T)
delta = abs(x1 - x)
x = x1
return x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment