function [xf,options] = fmin(funfcn,ax,bx,options,varargin)
%FMIN   Minimize function of one variable.
%   FMIN has been replaced with FMINBND.  FMIN currently works but  
%   will be removed in the future.  Use FMINBND instead.
%
%   X = FMIN('F',x1,x2) attempts to return a value of x which is a local 
%   minimizer of F(x) in the interval x1 < x < x2.  'F' is a string 
%   containing the name of the objective function to be minimized.
%
%   X = FMIN('F',x1,x2,OPTIONS) uses a vector of control parameters.
%   If OPTIONS(1) is positive, intermediate steps in the solution are
%   displayed; the default is OPTIONS(1) = 0.  OPTIONS(2) is the termination
%   tolerance for x; the default is 1.e-4.  OPTIONS(14) is the maximum
%   number of function evaluations; the default is OPTIONS(14) = 500.  
%   The other components of OPTIONS are not used as input control 
%   parameters by FMIN.  For more information, see FOPTIONS.
%
%   X = FMIN('F',x1,x2,OPTIONS,P1,P2,...) provides for additional
%   arguments which are passed to the objective function, F(X,P1,P2,...)
%
%   [X,OPTIONS] = FMIN(...) returns a count of the number of steps
%   taken in OPTIONS(10).
%
%   Examples
%       fmin('cos',3,4) computes pi to a few decimal places.
%       fmin('cos',3,4,[1,1.e-12]) displays the steps taken
%       to compute pi to about 12 decimal places.
%
%   See also FMINS.

%   Reference: "Computer Methods for Mathematical Computations",
%   Forsythe, Malcolm, and Moler, Prentice-Hall, 1976.

%   Original coding by Duane Hanselman, University of Maine.
%   Copyright 1984-2000 The MathWorks, Inc. 
%   $Revision: 5.19 $  $Date: 2000/06/02 00:11:23 $

% initialization
if nargin<4, options = []; end
options = foptions(options);
print = options(1);
tol = options(2);
if (~options(14))
    options(14) = 500; 
  end
if nargin < 3
  error('fmin requires three input arguments.')
end

% Convert to inline function as needed.
funfcn = fcnchk(funfcn,length(varargin));

%  Generate warning 
WarningStr=sprintf(...
['FMIN is obsolete and has been replaced by FMINBND.\n',...
'FMIN now calls FMINBND which uses the following syntax:\n',...
'   [X,FVAL,EXITFLAG,OUTPUT] = FMINBND(FUN,x1,x2,OPTIONS,P1,P2,...)\n',...
'Use OPTIMSET to define optimization options, or type\n',...
'''edit fmin'' to view the code used here.  FMIN will be\n',...
'removed in the future; please use FMINBND with the new syntax.\n']);

warning(WarningStr)

%  Setup options and call FMINBND
%  Uses options 1, 2, 14
%  Options 1
if print==0; Display='off';else;Display='iter';end
%  Options 2, 3, 14
TolX = options(2); MaxFunEvals = options(14);
Options = optimset('TolX',TolX,'MaxFunEvals',MaxFunEvals);
[xf,FVAL,EXITFLAG,OUTPUT] = fminbnd(funfcn,ax,bx,Options,varargin{:});
options(8)=FVAL;  %  This option was undocumented
options(10)=OUTPUT.funcCount;
