function[koren, iterace] = bisekce1(f, a, b, eps)

%% [koren, iterace] = bisekce1(f, a, b, eps)
%
% Metoda BISEKCE pro odhad korene nelinearni rovnice ve tvaru f(x)=0
%
% VSTUPNI PARAMETRY
% f ... textovy retezec
% a, b ... krajni body intervalu
% eps ... chyba
% VYSTUPNI PARAMETRY
% koren ... odhad reseni
% iterace ... pocet iteraci

x = a;
fa = eval(f); %fa = f(a) pre inline funkciu
x = b;
fb = eval(f);

if (fa*fb > 0 | b < a)
    error('Spatne zadany interval!')
end

s = 1/2*(a+b);
x = s;
fs = eval(f);
iterace = 0;

% zobrazeni iteraci
disp(['Iterace', blanks(4), 'aproximace'])
disp([num2str(iterace), blanks(10), num2str(s)])

while ((abs(fs) > eps) & (abs(a-b) > eps))
    if fa*fs < 0
        b = s;
        x = s;
        fb = eval(f);
    else a = s;
        x = s;
        fa = eval(f);
    end
    s = 1/2 * (a+b);
    x = s;
    fs = eval(f);
    iterace = iterace+1;
    
    % zobrazeni iteraci
    disp([num2str(iterace), blanks(10), num2str(s)])
end

koren = s;

end