positive solutions to Ax=b

7 views (last 30 days)
Christie
Christie on 19 May 2011
Commented: Steven Lord on 10 Apr 2018
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?
Walter Roberson
Walter Roberson on 19 May 2011
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)

Oleg Komarov
Oleg Komarov on 19 May 2011
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
Oleg Komarov
Oleg Komarov on 19 May 2011
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
Just in case someone visits here...now, it is possible to solve in this situation using lsqnonneg(A,b)
  1 Comment
Steven Lord
Steven Lord on 10 Apr 2018
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

Find more on Systems of Nonlinear Equations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!