Solve nonnegative least-squares constraint problem
Solves nonnegative least-squares curve fitting problems of the form
x = lsqnonneg(C,d)
x = lsqnonneg(C,d,options)
x = lsqnonneg(problem)
[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(...)
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,options)
minimizes
with the optimization options specified in the structure options
.
Use optimset
to set these options.
x = lsqnonneg(problem)
finds the minimum
for problem
, where problem
is
a structure described in Input Arguments.
Create the structure problem
by exporting
a problem from Optimization app, as described in Exporting Your Work.
[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 d-C*x
.
[x,resnorm,residual,exitflag] = lsqnonneg(...)
returns
a value exitflag
that describes the exit condition
of lsqnonneg
.
[x,resnorm,residual,exitflag,output]
= lsqnonneg(...)
returns a structure output
that
contains information about the optimization.
[x,resnorm,residual,exitflag,output,lambda]
= lsqnonneg(...)
returns the Lagrange multipliers in the
vector lambda
.
Function Arguments contains
general descriptions of arguments passed into lsqnonneg
.
This section provides function-specific details for options
and problem
:
| Use | |
| Level of display:
| |
| Termination tolerance on | |
problem |
| Matrix |
| Vector | |
| 'lsqnonneg' | |
| Options structure created using optimset |
Function Arguments contains
general descriptions of arguments returned by lsqnonneg
.
This section provides function-specific details for exitflag
, lambda
,
and output
:
| Integer identifying the
reason the algorithm terminated. The following lists the values of | |
| Function converged to a solution | |
| Number of iterations exceeded | |
| Vector containing the Lagrange
multipliers: | |
| Structure containing information about the optimization. The fields are | |
iterations | Number of iterations taken | |
algorithm |
| |
message | Exit message |
Compare the unconstrained least-squares solution to the lsqnonneg
solution
for a 4-by-2 problem.
C = [ 0.0372 0.2869 0.6861 0.7071 0.6233 0.6245 0.6344 0.6170]; d = [ 0.8587 0.1781 0.0747 0.8405]; [C\d, lsqnonneg(C,d)] ans = -2.5627 0 3.1108 0.6929 [norm(C*(C\d)-d), norm(C*lsqnonneg(C,d)-d)] ans = 0.6674 0.9118
The solution from lsqnonneg
does not fit
as well as the least-squares solution. However, the nonnegative least-squares
solution has no negative components.
The nonnegative least-squares problem is a subset of the constrained
linear least-squares problem. Thus, when C
has
more rows than columns (i.e., the system is overdetermined),
[x,resnorm,residual,exitflag,output,lambda] = ... lsqnonneg(C,d)
is equivalent to
[m,n] = size(C); [x,resnorm,residual,exitflag,output,lambda_lsqlin] = ... lsqlin(C,d,-eye(n,n),zeros(n,1));
except that lambda = -lambda_lsqlin.ineqlin
.
For problems greater than order 20, lsqlin
might
be faster than lsqnonneg
; otherwise lsqnonneg
is
generally more efficient.
[1] Lawson, C.L. and R.J. Hanson, Solving Least-Squares Problems, Prentice-Hall, Chapter 23, p. 161, 1974.