function chiadoi_tb (hamso,khoangnghiem,saiso)
    %

    if diff(khoangnghiem)<0
        khoangnghiem=swaplr(khoangnghiem);
    end;
    if diff(khoangnghiem)/2 < saiso
        disp ([' Khoang phan ly nghiem (', num2str(khoangnghiem(1)),';',num2str(khoangnghiem(2)),') co sai so nho hon sai so yeu cau']);
        disp (['Nghiem la: ', num2str(sum(khoangnghiem)/2),' +- ', num2str(diff(khoangnghiem)/2) '.']);
    else
        fdau=feval(hamso,khoangnghiem(1));
        sobuoc=ceil(log2(diff(khoangnghiem)/saiso));
        ss=diff(khoangnghiem)/2;

        % in tieu de bang tinh toan 
        scs=socscx(saiso);
        nformat=['%' sprintf('%1u',scs+5) '.' sprintf('%1u',scs+2)];
        plusstring(1:(scs+5)*6+6*3+8)='-';
        disp(plusstring);
        disp(['| buoc | ' printstr('dau',scs+5) ' | ' printstr('giua',scs+5) ' | ' printstr('cuoi',scs+5) ' | ' printstr('f(dau)',scs+5) ' | ' printstr('f(giua)',scs+5) ' | ' printstr('sai so',scs+5) ' |']);
        disp(plusstring);
        tableformat=['| %4u | ' nformat 'f | ' nformat 'f | ' nformat 'f | ' nformat 'f | ' nformat 'f | ' nformat 'f | '];

        for ii=1:sobuoc-1
            [khoangnghiemm, fdaum, fgiua, giua, ssm]=chiadoi1b(hamso,khoangnghiem,fdau);
            %inra = sprintf (tableformat, ii, khoangnghiem(1), giua, khoangnghiem(2), fdau, fgiua, ss);
            inra=[sprintf('| %4u', ii) ...
                  ' | ' printnumber(khoangnghiem(1),scs+5) ...
                  ' | ' printnumber(giua,scs+5) ...
                  ' | ' printnumber(khoangnghiem(2),scs+5) ...
                  ' | ' printnumber(fdau,scs+5) ...
                  ' | ' printnumber(fgiua,scs+5) ...
                  ' | ' printnumber(ss,scs+5) ' |'];
            fdau=fdaum;
            khoangnghiem=khoangnghiemm;
            ss=ssm;
            disp(inra);
        end;
        nghiem=sum(khoangnghiem)/2;
        % in dong cuoi cung cua bang
        inra=[sprintf('| %4u', ii) ...
                  ' | ' printnumber(khoangnghiem(1),scs+5) ...
                  ' | ' printnumber(nghiem,scs+5) ...
                  ' | ' printnumber(khoangnghiem(2),scs+5) ...
                  ' | ' printstr('---',scs+5) ...
                  ' | ' printstr('---',scs+5) ...
                  ' | ' printnumber(ss,scs+5) ' |'];
        disp(inra);
        % in vien duoi cua bang
        disp(plusstring);
        disp(' ');      
        
        % in ket qua
        scs=socscx(ss);
        nformat=['%' sprintf('%1u',scs+5) '.' sprintf('%1u',scs)];
        inra=sprintf([' Nghiem la: ' nformat 'f %1s ' nformat 'f'], nghiem,char(177), ss);
        disp (inra);
    end;
    
    
    
    
function [khoangnghiem, fdau, fgiua, giua, ss] = chiadoi1b (hamso,khoangnghiem,fdau)
    %
    giua=sum(khoangnghiem)/2;
    fgiua=feval(hamso,giua);
    if fgiua*fdau<0
        khoangnghiem=[khoangnghiem(1), giua];
    else
        khoangnghiem=[giua, khoangnghiem(2)];
        fdau=fgiua;
    end;
    ss=diff(khoangnghiem)/2;
    
function y=diff(x)
    y=x(2:end)-x(1:end-1);