function y=BS_class(a,b,N0)

close all

tol = 1e-6;  %N0 = 25;

% 

FA = FF(a);
FB = FF(b);
plot(a:(b-a)/20:b,FF(a:(b-a)/20:b))
drawnow
if FA*FB > 0,
  disp(' ')
  disp(['f(',num2str(a),') and f(',num2str(b),') have the same sign.'])
  disp('Try a different interval.')
  disp(' ')
  return;
end
 
i = 1; 
hold on
while i <= N0,
   p = a + (b-a)/2; 
   FP = FF(p);
   aa(i) = a;  bb(i) = b;
   y(i) = p; 
   if FP == 0 | (b-a)/2 < tol,
      x0 = p; break;
   end
   i = i + 1;
   if FA*FP > 0,
      a = p; FA = FP;
   else,
      b = p;
   end
  
   plot(p,0,'o')
   plot(p,FF(p),'x')
   p
   a
   b
   pause
end

x0 = a + (b-a)/2;
disp(' ')
disp(['The root is ',num2str(x0,11),' with a possible error of ',num2str((b-a)/2)])
disp(' ')
if i> N0,
   disp(['The Bisection method did not meet the'])
   disp(['tolerance ',num2str(tol),' after ',num2str(N0),' iterations']),
   disp(' ')
end

format long e,
disp(' n       a_n           p_n            b_n         F(p_n)         ')       
disp('---------------------------------------------------------------------------------------')
for kk=1:length(y)
   disp(sprintf(' %u   %11.8f   %11.8f   %11.8f   %11.8f   ', kk, aa(kk), y(kk), bb(kk), FF(y(kk)) ))
end
disp(' ')
end%Sampleprogram
%--------------------
function Fun = FF(x) 
Fun = x.^3 + 4*x.^2 - 10;
%Fun = exp(x) - x.^2 + 3*x -2;
end%function

