How do I get a positive solution from rref?

5 ビュー (過去 30 日間)
宏
2022 年 10 月 27 日
編集済み: Shantanu Dixit 2025 年 2 月 20 日
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 Center および File ExchangeLinear Algebra についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by