Metode pembagian python
def bisection(f, a, b, eps):
if f(a) * f(b) >= 0:
raise BaseException("Wrong interval!")
if a > b:
a, b = b, a
n = 0
x = (a + b) / 2
while b - a >= 2*eps:
if f(x) == 0:
return x, n
elif f(a) * f(x) < 0:
b = x
else:
a = x
x = (a + b) / 2
n += 1
return x, n
Elderdrinker