f(x) = x^2-35 # roots of this are +sqrt(35) and -sqrt(35) # We know there is a root between x=5 (f is negative) and x=6 (f is positive) a=5 b=6 # bisection n_bisection = 0 while b-a>.000000001: n_bisection += 1 c = (a+b)/2 if f(a)*f(c)>0: a=c else: b=c print('Root is between ',a.n(),' and ',b.n()) print(sqrt(35).n()) print('Number of steps for bisection: ',n_bisection) # Regula Falsi a=5 b=6 n_RF = 0 while abs(b-a)>.000000001: n_RF +=1 c = (a*f(b)-b*f(a))/(f(b)-f(a)) print(c.n()) a=b b=c print('Root is approximately ',b.n()) print(sqrt(35).n()) print('Number of steps for RF: ',n_RF)