% SOLVEXTANX  Solve x = tan(x) for first positive root using bisection.

f = @(x) x - tan(x);      % define the fcn

a = 4; b = 4.7;           % set initial bracket
s = sign(f(a));           % either +1 or -1 according to sign of f(a)
n = 0;
while (b-a)/2 > 1.0e-5
  fprintf('  [a_%2d, b_%2d] = [%f, %f]\n', n, n, a, b)
  c = (a+b)/2;
  if sign(f(c)) == s      % now this works if  f(a)>0  *or* if  f(a)<0
    a = c;
  else
    b = c;
  end
  n = n+1;
end
fprintf('final estimate  c = %f  has maximum error %e\n',c,(b-a)/2)
