How do I get a positive solution from rref?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Shantanu Dixit
le 20 Fév 2025
Modifié(e) : Shantanu Dixit
le 20 Fév 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 commentaires
Voir également
Catégories
En savoir plus sur Linear Algebra dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!