% Simple bisection for finding roots of functions of a single variable.
% Use as starting point, add comments and elaborations of basic code as needed.
% FofX the function whose root we are finding (example below), to be included in the Matlab path/
function root=bisection(xL,xR)
%input checking
if FofX(xL)*FofX(xR)>0; display ('Initial interval contains even number of roots');return;end
tolerance = 1e-12;
accuracy=100*tolerance;

while accuracy> tolerance
xmiddle=(xL+xR)/2;
if FofX(xL)*FofX(xmiddle)<0; xR=xmiddle;else xL=xmiddle;end;
accuracy=abs(FofX(xmiddle));
end

root=xmiddle;
end

function output=FofX(x)
output=x-cos(x);
end