% Evaluate root of cos(x) = x with precision 10^(-8).
err = 10^(-8);
a = 0;
b = pi/2;
c = (a+b)/2;
while (b-a>err)
    if sign((cos(a)-a))*sign(cos(c)-c)<0
        b = c;
    else
        a = c;
    end
    c = (a+b)/2;
end
c