I have the following function written in python 3
def nullstelle(f,a,b,counter=0,TOL=10 ** -4):
counter = counter + 1
if counter <= 100:
g = f((a + b)/2)
if f(a) * g <= 0:
b = (a + b)/2
else:
a = (a + b)/2
if abs(a-b) <= 2*TOL:
return (a,b)
else:
nullstelle(f,a,b,counter,TOL)
else:
return (a,b)
my problem is, that for the input
def f(x):
return x ** 3 -2
nullstelle(f,0,3)
it does not return anything. I really do not understand how this is possibly.
Im sorry if this looks like a trivial question to you guys, but programming is absolutely not my main field of interest and I know nearly nothing about it (yet).