% Solve f(x)=(x/2)^2-sin(x)=0 for x in [1.5, 2.0]
%This example ASSUMES that f(a)<0<f(b)...

x = 1.5:0.001:2;
f = inline('(x/2).^2-sin(x)','x');
a = 1.5;
b = 2.0;
for k = 0:9
plot(x,f(x),'k-','linewidth',2)
axis([1.45 2.05 -0.5 .15])
grid on
hold on
plot([a b],f([a b]),'ko','linewidth',5)
hold off
m = (a+b)/2
if( f(m) < 0 )
a = m;
else
b = m;
end
pause
print('-depsc',['bisec' int2str(k) '.eps'],'-f1');
end
