function compare(fcn, a, b, tol, N,dfcn)
% Examples:
%   compare('sin(x)',-.1,.5,1e-5,20,'cos(x)');
%   compare('exp(x)-exp(1)',0,2,1e-3,20,'exp(x)');
%   compare('exp(x)-exp(1)',-1,2,1e-3,20,'exp(x)');  
%   compare('exp(x)-exp(1)',1/2,2,1e-3,20,'exp(x)');  
%   compare('1-cos(x)',-.1,.5,1e-5,20,'sin(x)');

  
  clf
  disp('Bisection:')
  [itB,rootB,xnB]=bisect(fcn,a,b,tol,N);
  if rootB == rootB
    disp(rootB)
  else
    disp(' ')
  end
  resB=abs(feval(inline(fcn),xnB));
  semilogy([0:itB],resB,'-go'), hold on
  xlabel('Iteration'), ylabel('|f(x_n)|'),
  title(sprintf('Semilog plot of approximations to roots of %s, a=%g, b=%g with error < %g',fcn,a,b,tol))
  legend(sprintf('Bisection (%d)',itB)),  pause

  disp('Secant:')
  [itS,rootS,xnS]=secant(fcn,.9*a,a,tol,N);
  if rootS == rootS
    disp(rootS)
  else
    disp(' ')
  end
  resS=abs(feval(inline(fcn),xnS));
  semilogy([0:itS+1],resS,'-.b*')
  legend(sprintf('Bisection (%d)',itB),sprintf('Secant (%d)',itS)),  pause

  disp('Newton:')
  if (nargin<6)
  dfcn=maple('diff',fcn,'x');  
  end
  [itN,rootN,xnN]=newton(fcn,dfcn,a,tol,N);
  if rootN == rootN
    disp(rootN)
  else
    disp(' ')
  end
  resN=abs(feval(inline(fcn),xnN));
  semilogy([0:itN],resN,'--rs')
  legend(sprintf('Bisection (%d)',itB),sprintf('Secant (%d)',itS),...
	 sprintf('Newton (%d)',itN))

