clear; clc; format long;

a = 1; b = 2; eps = 1e-9;
while b - a > eps
    c = (a + b) / 2;

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

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

root = c
residual = fc
    