%%BISECTION.M  Bisection algorithm for nonlinear root-finding. 
% NH 2019.

f = @(t) 8 - 4.5*(t - sin(t)); % Define function
a = 2; b = 3;                  % Define initial interval
tol = 1e-4;                    % Define tolerance
fc = inf;                      % Start iteration
while ( abs(fc) > tol )        % <-- Different stopping criteria to bisection.
    c = (a*f(b)-b*f(a))/(f(b)-f(a)); % <-- Inefficient. Too many function evals!
    fc = f(c);
    disp([a b c fc (b-a)/2])   % Display values
    if ( f(a)*fc < 0 )          
        b = c;
    else
        a = c;
    end
end

