% Bisection
% a = left end point of interval containing the root
% b = right  end point of interval containing the root
% tolx = error tolerance in x
% tolf = error tolerance in the function value
% N = the current iteration number
% Nmax = maximum number of iterations
% fcn.m is the name of the file containing the function
format long
a=1;
b=4;
N=1;
Nmax = 50;
tolx = .001;
tolf = 0.000001;
fa = feval('fcn',a);
fb = feval('fcn',b);
m =(a+b)/2;
fm = feval('fcn',m);
while (abs(b-a) > tolx) & (abs(fm) > tolf) & (N < Nmax)
[N,a,b,m,fm]
 if fa*fm <=0;
  b = m;
  fb = fm;
 else a = m;
  fa= fm;
end
 m = (a+b)/2;
 fm = feval('fcn', m);
 N= N+1;
end
