| MATLAB Function Reference | Search  Help Desk |
| lsqnonneg | Examples See Also |
Linear least squares with nonnegativity constraints
Syntax
x = lsqnonneg(C,d) x = lsqnonneg(C,d,x0) x = lsqnonneg(C,d,x0,options) [x,resnorm] = lsqnonneg(...) [x,resnorm,residual] = lsqnonneg(...) [x,resnorm,residual,exitflag] = lsqnonneg(...) [x,resnorm,residual,exitflag,output] = lsqnonneg(...) [x,resnorm,residual,exitflag,output,lambda] = lsqnonneg(...)
Description
x = lsqnonneg(C,d)
returns the vector x that minimizes norm(C*x-d) subject to x >= 0. C and d must be real.
x = lsqnonneg(C,d,x0)
uses x0 as the starting point if all x0 >= 0; otherwise, the default is used. The default start point is the origin (the default is used when x0==[ ] or when only two input arguments are provided).
x = lsqnonneg(C,d,x0,options)
minimizes with the optimization parameters specified in the structure options. You can define these parameters using the optimset function. lsqnonneg uses these options structure fields:
Display - Level of display. off displays no output; iter displays output at each iteration; final displays just the final output.
TolX - Termination tolerance on x.
[x,resnorm] = lsqnonneg(...)
returns the value of the squared 2-norm of the residual: norm(C*x-d)^2.
[x,resnorm,residual] = lsqnonneg(...)
returns the residual, C*x-d.
[x,resnorm,residual,exitflag] = lsqnonneg(...)
returns a value exitflag that describes the exit condition of lsqnonneg:
> 0 indicates that the function converged to a solution x.
0 indicates that the iteration count was exceeded. Increasing the tolerance (TolX parameter in options) may lead to a solution.
< 0 indicates that the function did not converge to a solution.
[x,resnorm,residual,exitflag,output] = lsqnonneg(...)
returns a structure output that contains information about the operation:
output.iterations - The number of iterations taken.
output.algorithm - The algorithm used.
[x,resnorm,residual,exitflag,output,lambda] = lsqnonneg(...)
returns the dual vector lambda, where lambda(i)<=0 when x(i) is (approximately) 0, and lambda(i) is (approximately) 0 when x(i)>0.
Examples
Compare the unconstrained least squares solution to thelsqnonneg solution for a 4-by-2 problem:
C =The solution from0.03720.28690.68610.70710.62330.62450.63440.6170 d =0.85870.17810.07470.8405 [C\dlsqnonneg(C,d)]= -2.562703.11080.6929 [norm(C*(C\d)-d)norm(C*lsqnonneg(C,d)-d)]=0.66740.9118
lsqnonneg does not fit as well (has a larger residual), but has no negative components.
Algorithm
lsqnonneg uses the algorithm described in [1]. The algorithm starts with a set of possible basis vectors and computes the associated dual vector lambda. It then selects the basis vector corresponding to the maximum value in lambda in order to swap out of the basis in exchange for another possible candidate. This continues until lambda <= 0.
See Also
The arithmetic operator\, optimset
References
[1] Lawson, C.L. and R.J. Hanson, Solving Least Squares Problems, Prentice-Hall, 1974, Chapter 23, p. 161.