Skip to content

Instantly share code, notes, and snippets.

@Ismael-VC
Last active August 29, 2015 14:06
Show Gist options
  • Save Ismael-VC/987294967490c5a1cb09 to your computer and use it in GitHub Desktop.
Save Ismael-VC/987294967490c5a1cb09 to your computer and use it in GitHub Desktop.
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