A = @(x) [[1,2,3,x];... [4,5,x,6];... [7,x,8,9];... [x,10,11,12]]; f = @(x) det(A(x))-1000; % plot the function to "visually" bracket the root X=linspace(9,10,100); plot(X,arrayfun(f,X)); tol = 1.0E-06; a = 9; b = 10; fa = f(a); fb = f(b); assert(fa*fb<0); iter = 0; while b-a > tol, iter = iter + 1; c = (b+a)/2; fc = f(c); fprintf('Iter: %4d, a: %e, f(a): %e, c: %e, f(c): %e, b: %e, f(b): %e\n',... iter,a,fa,c,fc,b,fb); if fc == 0.0 % in reality this should be fc < tol_fun break; end if fa*fc < 0 b = c; fb = fc; else a = c; fa = fc; end end fprintf('Backward error: %e\n', fc);