Bisection 1

%bisection
%Author: Minster
%this program uses bisection to determine the root of an algorithms. The
%sign of F(a) and f(b) must be different

%f(x) = x^2 -1
a=0.5;
b=3;
N=10; %number of iterations

fa=a^2-1;
fb=b^2-1;

for k=1:N,
c=(a+b)/2;
fc=c^2-1;
if sign(fc)== sign(fa),
a=c;
fa=fc;
else b=c;
fb=fc;
end
c
end
a
b
root = (a+b)/2
froot = root^2-1