function bissection() close all; clear all; bissec(0,2,10e-6,50); end function bissec(a,b,tol,nmax); n = 0; delta = tol + 1; if (f(a)*f(b) > 0) error('The sign of the functions at the extrema must be different'); end while abs(delta) >= tol && n <= nmax delta = (b-a)/2; x = a + delta; n = n + 1; if (f(x)*f(a) > 0) a = x; else b = x; end fprintf('\n x = %21.14e (Estimated error %21.14e at %i iteration ) ',x,abs(delta),n); end if (n == nmax) error('aie'); end end function y = f(x) y = x .* sin(x) - 1; end