Last active
August 29, 2015 14:06
-
-
Save Ismael-VC/987294967490c5a1cb09 to your computer and use it in GitHub Desktop.
This file contains 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 horner(p, x): | |
'''Evalúa p(x) y p'(x), donde el polinomio p está representado como una | |
lista donde cada p[k] es el coeficiente de x**k''' | |
r, d = 0, 0 | |
for k in range(len(p) - 1, 0, -1): | |
r = x*r + p[k] | |
d = x*d + k*p[k] | |
return x*r + p[0], d | |
def newton(p, x, eps): | |
'''Implementa el metodo de newton para resolver p(x) == 0 donde p es la | |
lista de los coeficoentes de un polinomio''' | |
while True: | |
a,b = horner(p, x) | |
d = a/b | |
x -= d | |
if abs(d) <= eps: break | |
return x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment