function [x,w] = nnls(E,f,tol)
%NNLS   Non-negative least-squares.
%   NNLS has been replaced with LSQNONNEG.  NNLS currently works but  
%   will be removed in the future.  Use LSQNONNEG instead.
%
%   X = NNLS(A,b) returns the vector X that minimizes NORM(A*X - b)
%   subject to X >= 0.   A and b must be real.
%
%   A default tolerance of TOL = MAX(SIZE(A)) * NORM(A,1) * EPS
%   is used for deciding when elements of X are less than zero.
%   This can be overridden with X = NNLS(A,b,TOL).
%
%   [X,W] = NNLS(A,b) also returns dual vector W where w(i) < 0
%   when x(i) = 0 and w(i) is approximately 0 when x(i) > 0.
%
%   See also LSCOV, SLASH.

%   L. Shure 5-8-87
%   Revised, 12-15-88,8-31-89 LS.
%   Copyright 1984-2000 The MathWorks, Inc. 
%   $Revision: 5.11 $  $Date: 2000/06/01 02:04:15 $

% Reference:
%  Lawson and Hanson, "Solving Least Squares Problems", Prentice-Hall, 1974.

if nargin<2, error('Not enough input arguments.'); end
if ~isreal(E) | ~isreal(f), error('A and b must be real.'); end

% initialize variables
if nargin < 3
    tol = 10*eps*norm(E,1)*length(E);
end

%  Generate warning 
WarningStr=sprintf(...
['NNLS is obsolete and has been replaced by LSQNONNEG.\n',...
'NNLS now calls LSQNONNEG which uses the following syntax:\n',...
'   [X,RESNORM,RESIDUAL,EXITFLAG,OUTPUT,LAMBDA] = lsqnonneg(A,b,X0,Options);\n',...
'Use OPTIMSET to define optimization options, or type\n',...
'''edit nnls'' to view the code used here.  NNLS will be\n',...
'removed in the future; please use NNLS with the new syntax.\n']);

warning(WarningStr)

%  Setup options and call LSQNONNEG
Options = optimset('Display','none','TolX',tol);
[x,RESNORM,RESIDUAL,EXITFLAG,OUTPUT,w] = lsqnonneg(E,f,[],Options);

