function [root, iterations, errors] = bisection_method(guess1, guess2, max_iterations, tolerance) if functionDemo(guess1) * functionDemo(guess2) >= 0 error("The guess does not satisfy the required conditions"); endif iterations = 0; errors = []; prevGuess = 0; while iterations < max_iterations c=(guess+guess2)/2; if functionDemo(guess1)*functionDemo(guess2)<0 guess2=c; else guess1=c; endif if iterations>1 error=(c-preguess)/c; preguess=c; errors=[errors,error]; else preguess=c; endif iterations++; endwhile root=c; endfunction