% Find approximate root of x^3 - 2*x - 2 = 0 with error 10^(-3) using bisection method

a = 0;
b = 2;
epsilon = 10^(-3);
n = floor(log((b-a)/epsilon)/log(2));
for k = 1:n
    c = (a+b)/2;
    if ((a^3-2*a-2)*(c^3-2*c-2)<0)
        b = c;
    else
        a = c;
    end
end
c = (a+b)/2