blob: 16aa65de5b98b69bc8eced566e8a257495d045ee (
plain) (
blame)
1
2
3
4
5
6
7
8
|
def ratpoison(f, df, x, es=10**-8, imax=20):
ea, i = 1, 0
while ea > es and i < imax:
i += 1
xold, x = x, x - f(x)/df(x)
if f(x) == 0: return x, 0, 0, i
if x: ea = abs((x - xold) / x)
return x, f(x), ea, i
|