[x,resnorm,residual]
= lsqnonneg(___), for any previous syntax,
additionally returns the value of the squared 2-norm of the residual, norm(C*x-d)^2,
and returns the residual d-C*x.

[x,resnorm,residual,exitflag,output]
= lsqnonneg(___) additionally returns a value exitflag that
describes the exit condition of lsqnonneg, and
a structure output with information about the optimization
process.

For compatibility, the length of d must equal
the number of rows of C.

Example: d = [1;-6;5]

Data Types: double

options — Optimization options structure such as optimset returns

Optimization options, specified as a structure such as optimset returns.
You can use optimset to set
or change the values of these fields in the options structure. See Set Options for
detailed information.

Display

Level of display:

'notify' (default) displays output
only if the function does not converge.

Squared residual norm, returned as a nonnegative scalar. Equal
to norm(C*x-d)^2.

residual — Residual real vector

Residual, returned as a real vector. The residual is d - C*x.

exitflag — Reason lsqnonneg stopped integer

Reason lsqnonneg stopped, returned as an
integer.

1

Function converged to a solution x.

0

Number of iterations exceeded options.MaxIter.

output — Information about the optimization process structure

Information about the optimization process, returned as a structure
with fields:

iterations

Number of iterations taken

algorithm

'active-set'

message

Exit message

lambda — Lagrange multipliers real vector

Lagrange multipliers, returned as a real vector. The entries
satisfy the complementarity condition x'*lambda = 0.
This means lambda(i) < 0 when x(i) is
approximately 0, and lambda(i) is
approximately 0 when x(i) > 0.

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 to
swap it out of the basis in exchange for another possible candidate.
This continues until lambda ≤ 0.

References

[1] Lawson, C. L. and R. J. Hanson. Solving
Least-Squares Problems. Upper Saddle River, NJ: Prentice
Hall. 1974. Chapter 23, p. 161.