function ShowBisection()
% Illustrates the method of bisection.
% Plot f(x) = (x+2)(x-.5)(x-2)...
close all
N = 500;
L = -2.3;
R = 2.3;
xVals = linspace(L,R,N);
yVals = MyF(xVals);
plot([L-1 R+1],[0 0],'k',xVals,yVals)
title('f(x) = (x + 2)*(x - .5)*(x - 2)','fontsize',16)
shg
% Enter and display a bracketing interval...
xlabel('Click in Bracketing Interval Endpoints','fontsize',16)
hold on
[a,y] = ginput(1);
plot(a,0,'.r','Markersize',20)
[b,y] = ginput(1);
plot(b,0,'.r','Markersize',20)
plot([a,b],[0 0],'r','linewidth',3)
xlabel(' ')
% Compute a root and display...
xStar = Bisection(@MyF,a,b,.0001);
plot(xStar,0,'.k','Markersize',20)
hold off

function y = MyF(x)
y = (x+2).*(x-.5).*(x-2);