function[koren, iterace] = bisekce2(f, a, b, eps) %% [koren, iterace] = bisekce2(f, a, b, eps) % % Metoda BISEKCE pro odhad korene nelinearni rovnice ve tvaru f(x)=0 % % VSTUPNI PARAMETRY % f ... inline funkce % a, b ... krajni body intervalu % eps ... chyba % VYSTUPNI PARAMETRY % koren ... odhad reseni % iterace ... pocet iteraci fa = f(a); fb = f(b); if (fa*fb >= 0 | b < a) error('Spatne zadany interval!') end s = 1/2*(a+b); fs = f(s); 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; fb = f(b); else a = s; fa = f(a); end s = 1/2 * (a+b); fs = f(s); iterace = iterace+1; % zobrazeni iteraci disp([num2str(iterace), blanks(10), num2str(s)]) end koren = s; end