How do I get a positive solution from rref?
1 view (last 30 days)
Show older comments
I want to solve a linear combination from a table and a vector, but after solving it (using rref())always gives me some negative numbers. How do i get only positive feedback from it?
0 Comments
Answers (1)
Shantanu Dixit
on 20 Feb 2025
Edited: Shantanu Dixit
on 20 Feb 2025
Hi,
If I understand your query correctly, you want to solve an exact system 'Ax=b' (where 'A' is the table and 'b' is the vector) while ensuring 'x≥0'. The 'rref' function only computes the reduced row echelon form and does not enforce nonnegativity.
To achieve this, you can use 'linprog' which allows you to impose 'x≥0' by setting lower bounds as an input argument 'lb'. Here’s a simple example solving a 3×2 system using 'linprog':
f = zeros(size(A,2),1); % Trivial objective function: minimize 0'*x
Aeq = A; % Equality constraint: A*x = b
beq = b;
lb = zeros(size(A,2),1); % Lower bound: x >= 0
options = optimoptions('linprog','Display','none');
x = linprog(f, [], [], Aeq, beq, lb, [], options);
If such a solution exists then 'linprog' will return it as 'x' else an empty vector is returned.
You can refer to linprog for additional details: https://www.mathworks.com/help/optim/ug/linprog.html
Hope this helps!
0 Comments
See Also
Categories
Find more on Linear Algebra in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!