% BISECT4A  Solve polynomial root problem by bisection.

f = @(x) x.^4 - 2 * x.^3 - 4 * x.^2 + 4 * x + 4;  % define the fcn

a = -2;                 % set initial bracket
b = -1;
[f(a) f(b)]             % print out f values; show we have a bracket
for n = 1:7
  c = (a+b)/2;
  if f(c) > 0           % note that  f(a)>0,  so if  f(c)>0  then
    a = c;              %   c is the new a
  else
    b = c;
  end
end

[a b]                   % show:  final bracket
(b - a)/2               %        half-length of bracket (=max err)
[c f(c)]                %        estimate of root and f value
