How do I get a positive solution from rref?
14 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Shantanu Dixit
am 20 Feb. 2025
Bearbeitet: Shantanu Dixit
am 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 Kommentare
Siehe auch
Kategorien
Mehr zu Linear Algebra finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!