% Function to find a zero of. f = @(x) x.^2 - 2; % Call the bisection routine with the interval [0,2] and tolerance 1e-12. [x,iter] = bisection_method(0,2,f,1e-12); % Plot how the iteration converges (the true root is sqrt(2)) semilogy(1:iter,abs(x-sqrt(2)),'x-'); xlabel('Iteration count'); ylabel('$|x-\tilde{x}|$','Interpreter','Latex'); title('Convergence results for bisection');