Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to solve $Ax = b$ subject to the constraint that all of the elements of $x$ are non-negative. If such a solution does not exist, I want to find non-negative $x$ such that the quadratic form $(Ax - b)^T (Ax-b)$ is minimized. What kind of algorithm will let me do this?

share|cite|improve this question
what are dimensions of matrix $A$? Is it square, more columns than rows or vice versa? – mpiktas Apr 16 '11 at 18:14
up vote 2 down vote accepted

Put differently, you want to solve the following optimization problem $$ \min_x \|Ax-b\|^2\ \text{s. t.}\ x\geq 0. $$ This is a quadratic and convexly constrained minimization problem which can be solved in many ways. There are several software packages around to do the task, for example the quadprog routine of the Matlab Optimization toolbox should work here. However, the choice should at least depend on the size and the type of the matrix.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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