function bisect_test ( )

% MATLAB version of Script for trying out BISECT from page 82 of conte/deboor
%
%  Reference:
%
%    Samuel Conte, Carl de Boor,
%    Elementary Numerical Analysis,
%    Third Edition,
%    SIAM, 2017,
%    ISBN: 978-1-611975-19-2.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'bisect_test\n' );
  fprintf ( 1, '  Test bisect():\n' );

  for j=1:3
    switch j
    case 1, [A,B,IFLAG] = bisect(@F, 2, 3, 1.e-6);
    case 2, [A,B,IFLAG] = bisect(@F, 1, 2, 1.e-17);
       fprintf('IFLAG = %d (should be 1)\n',IFLAG)
    case 3, [A,B,IFLAG] = bisect(@F, 1, 2, 1.e-6);
    end
    if (IFLAG >= 0)
      XI = (A+B)/2;
      ERROR = abs(A-B)/2;
      fprintf(' The zero is %e  plus/minus  %e\n',[XI,ERROR])
    end
  end

  return
end
function fx = F(X)
fx = -1 - X*(1-X*X);  % using .* instead of * would make it possible to
                      % obtain the values at all the entries of an
                      % entire array X in one fell swoop.
fprintf('  X = %e,  F(X) = %e\n', [X, fx])
end
