Created
March 7, 2017 19:07
-
-
Save gibsramen/8ad4af5a1f208fd9f669cf4178e419fb to your computer and use it in GitHub Desktop.
Newton-Raphson Code
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
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