clear; clc; format long;

% f(x) = x ^ 3 - x - 2
a = 1;
b = 2;
eps = 1e-10;
iter = 0;
while b - a > eps
    iter = iter + 1;
    c = (a + b) / 2;

    fa = a ^ 3 - a - 2;
    fb = b ^ 3 - b - 2;
    fc = c ^ 3 - c - 2;

    % if (fa > 0 && fc < 0) || (...)
    if fa * fc < 0
        b = c;
    else
        a = c;
    end
end
c
fc
iter


