% BISEC bisection method
%
function [ntol,x] = bisec(a,b,tol)
ntol = ceil(log((b-a)/tol)/log(2));
for n=1:ntol
    x=(a+b)/2;
    fx=subs(f(x));
    if fx<0
        a=x;
    else
        b=x;
    end
end

% function y = f(x)
% y=0.5*x - sin(x);

function y = f(s)

[t,f] = ode45('fun1',[0 pi/4],[0 s]);
y = f(length(f(:,1)),1)-1;
