def bifurcatio eps global counter x0 delta eps if eps return if x0 del

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
def bifurcatio(a, b, eps, f):
global counter
x0 = (b + a)/2.0
delta = eps/2.0
if b - a < 2 * eps:
return (a + b)/2.
if f(x0 - delta) == f(x0 + delta):
return (a + b)/2.
else:
if f(x0 - delta) < f(x0 + delta):
counter += 1
return bifurcatio(a, x0, eps, f)
else:
counter += 1
return bifurcatio(x0, b, eps, f)