positive solutions to Ax=b
7 views (last 30 days)
Show older comments
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
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"?
Answers (2)
Oleg Komarov
on 19 May 2011
x = lsqlin(A,b,[],[],[],[],0)
Least squares with lower bounded x's to 0.
2 Comments
Oleg Komarov
on 19 May 2011
We used it once to carry out asset allocation analysis a la Sharpe 1992.
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
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.
See Also
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!