function p = bisection_short(f,v)
%BISECTION_SHORT(f,v)
%   Runs the bisection rootfinding algorithm for the function
%   f on the starting interval v=[a,b].
%
%   (C) 2010/09/21 by Benjamin Seibold

fv = f(v); % values at interval boundaries
if prod(fv)>=0, error('No opposite signs.'), end
while 1
    p = sum(v)/2; fp = f(p); % position and value of midpoint
    if diff(v)<1e-12&&abs(fp)<1e-12||fp==0, break, end % stopping criterion
    i = (sign(fp)~=sign(fv(1)))+1; % index to be replaced by midpoint
    v(i) = p; fv(i) = fp; % cut interval in half
end

