How do I get a positive solution from rref?

3 次查看(过去 30 天)
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?

回答(1 个)

Shantanu Dixit
Shantanu Dixit 2025-2-20
编辑:Shantanu Dixit 2025-2-20
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!

类别

Help CenterFile Exchange 中查找有关 Linear Algebra 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by