x = nnls(A,b)x = nnls(A,b,tol)[x,w] = nnls(A,b)[x,w] = nnls(A,b,tol)
x = nnls(A,b) solves the system of equations
in a least squares sense, subject to the constraint that the solution vector x have nonnegative elements
x = nnls(A,b,tol) specifies a tolerance tol, that determines when an element is less than 0. By default, tol is
max(size(A))*norm(A,1)*eps
[x,w] = nnls(...) returns the dual vector w. The elements of x and w are related by
nnls solution for a 4-by-2 problem:
The solution fromA=0.0372 0.28690.6861 0.70710.6233 0.62450.6344 0.6170b=0.85870.17810.07470.8405[A\b nnls(A,b)] =-2.5625 03.1106 0.6929[norm(A*(a\b)-b) norm(A*nnls(a,b)-b)] =0.6677 0.9119
nnls does not fit as well, but has no negative components.
nnls uses the algorithm described in [1], Chapter 23. The algorithm starts with a set of possible basis vectors, computes the associated dual vector w, and selects the basis vector corresponding to the maximum value in w to swap out of the basis in exchange for another possible candidate, until w <= 0.
\
(c) Copyright 1994 by The MathWorks, Inc.