function [x0,it] = bisect_rov(fun,a,b,tol)
% [x0,it] = bisect_rov(fun,a,b,tol)
%
% funkce nalezne koren rovnice 
%      f(x) = 0
% metodou puleni intervalu
%
% x0 ... minimum
% it ... pocet iteraci
%
% fun ... f(x) zadana ve stringu 
% a,b ... meze intervalu
% tol ... pozadovana absolutni presnost


fa = feval(fun,a);
fb = feval(fun,b);

if (fa*fb>0)
   error('funkce nema v intervalu <a,b> reseni')
end


it = 0;

while (b - a) >= tol 
    c=(a+b)/2;
	fc=feval(fun,c);
 
   if (fa*fc<0)
      b=c; 
      fb=fc; 
   elseif (fc*fb<0)
      a=c; 
      fa=fc;
   else
   	 a=c; b=c;
   end;
   
   it = it + 1; 
end

x0 = c;

% end