positive solutions to Ax=b

Hi,
I am trying to solve a set of linear equations in the form Ax=b. Solving this by using the command x=A\b generates both positive and negative values and in my case I only want positive values. Is there a way to solve for x with the constraint that the solution be positive?

2 Comments

bym
bym on 19 May 2011
are you doing it numerically or symbolically?
What size is A ? If it is wider than a single column then \ is going to give multiple output values: in such a case, what would it mean to you to "only want positive values"?

Sign in to comment.

Answers (2)

x = lsqlin(A,b,[],[],[],[],0)
Least squares with lower bounded x's to 0.

2 Comments

bym
bym on 19 May 2011
very good, did not know this one. +1 vote
We used it once to carry out asset allocation analysis a la Sharpe 1992.

Sign in to comment.

NN Misra
NN Misra on 10 Apr 2018

0 votes

Just in case someone visits here...now, it is possible to solve in this situation using lsqnonneg(A,b)

1 Comment

Almost. As the name implies, the elements of the output of lsqnonneg will be non-negative. The original question asked for positive elements in the solution. If 0 is an acceptable value to have in the solution, you can use lsqnonneg.

Sign in to comment.

Categories

Asked:

on 19 May 2011

Commented:

on 10 Apr 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!