% demonstracni priklad pro predvedeni metody bisekce
% sepsal Jan Nejedly 2003
%
% ukazka bude provedena na f(x)=(x/2)^2-sin(x)

a=1;
b=4;
kroku=20;
presnost=.001;

x=a:0.01:b;
y=(x/2).^2-sin(x);
plot(x,y);
hold on;

for i=1:kroku
  new=(a+b)/2;
  pos=(new/2)^2-sin(new);
  posa=(a/2)^2-sin(a);
  posb=(b/2)^2-sin(b);
  if abs(pos)<presnost
     disp('Mame nulu');
     new
     plot(new,pos,'rx');
     break;
  else
     if sign(pos)==sign(posa)
        plot(new,pos,'gx');
	a=new;
     else
        plot(new,pos,'bx');
	b=new;
     end
  end;
  pause;
end;
     	