%
% This script demonstrates the use of the bisect function.
%
%  Plot the function defined in func.m:
%
x = linspace(-2,10,401);
y = func(x);
clf
plot(x,y)
hold on
grid on

%
% Set the error tolerance.
%
ftol = 1e-5;

disp('Looking for the root in [-2,0]')
% Use bisect to find the first root
x1 = bisect('func',-2,0,ftol);
disp(sprintf('x1=%12.8f\n',x1))
plot(x1,0,'ro','linewidth',2)

disp('Looking for the root in [0,4]')
% Use bisect to find the second root
x2 = bisect('func',0,4,ftol);
disp(sprintf('x2=%12.8f\n',x2))
plot(x2,0,'ro','linewidth',2)

disp('Looking for the root in [4,10]')
% Use bisect to find the third root
x3 = bisect('func',4,10,ftol);
disp(sprintf('x3=%12.8f\n',x3))
plot(x3,0,'ro','linewidth',2)
