function result = functionDemo(x) result = x^3 - 23*x^2 + 142*x - 120; end function [root, iterations, errors] = bisection_method(guess1, guess2, max_iterations, tolerance) if functionDemo(guess1) * functionDemo(guess2) >= 0 error("The guesses do not satisfy the required conditions"); end iterations = 0; errors = []; prevGuess = 0; while iterations < max_iterations root = (guess1 + guess2) / 2; error_estimate = abs(root - prevGuess); errors = [errors; error_estimate]; if error_estimate < tolerance break; end prevGuess = root; if functionDemo(guess1) * functionDemo(root) < 0 guess2 = root; else guess1 = root; end iterations = iterations + 1; end endfunction [root, iterations, errors] = bisection_method(11, 20, 100, 1e-6); % Plotting the graph of relative errors vs. iterations figure; plot(1:length(errors), errors, '-o'); xlabel('Iterations'); ylabel('Relative Error'); title('Relative Errors vs. Iterations'); grid on;