There is a least-squares problem. It can be solved using backslash in Matlab.
If Ax = b, then x = A \ b.
Let's assume that I have the same problem, but all x must be non-negative (>=0). How can I solve this problem in Matlab by analogy with the previous one (without non-negativity constraints)? I think it can be somehow connected with the active set method.
I know that the non-negative least squares problem can be easily solved with Matlab Optimization toolbox or CVX or in many other ways. But still I'm curious about solving it by analogy with a straight-forward least-squares method (with backslash).
Could anyone help me please?


2 Answers 2


MATLAB has a built-in function lsqnonneg() which is an implementation of the active set method described in the book "Solving Least Squares Problems" by Lawson and Hanson (1974)

The \ solution of linear least squares problems in MATLAB is done by a variety of different algorithms depending on the exact structure of the problem. None of them are particularly similar to the active set method used in lsqnonneg().


Not sure if this helps, but the trick is that Lawson & Hanson's algorithm selects a special subset of columns from A such that when you perform regression x = A(:,subset) \ b resulting coefficients are all non-negative.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.