3 variable Linear function problem

7 ビュー (過去 30 日間)
Mohamed Rashad
Mohamed Rashad 2021 年 8 月 12 日
コメント済み: Mohamed Rashad 2021 年 8 月 16 日
In a 3 variable Linear function Optimization problem, how to write the code if two variable bounds are defined (zero to infinity) and the third variable is not defined (-infinity to +infinity) ?
For reference: Maximize Z = x1 - 2x1 + 3x3
Subject to x1 + X2 + x3 <= 7 x1 - X2 + x3 >= 2 3x1 - x2 - 2x3 = -5 x1,x2 >= 0

採用された回答

Alan Weiss
Alan Weiss 2021 年 8 月 15 日
In linprog set
lb = [0 0 -Inf];
You will have to take the negative of your objective function vector in order to maximize.
Alternatively, formulation is easier if you use the problem-based approach:
prob = optimproblem('ObjectiveSense','maximize');
x = optimvar('x',3,'LowerBound',[0 0 -Inf]);
prob.Objective = x(1) - 2*x(2) + 3*x(3);
prob.Constraints.cons1 = sum(x) <= 7;
prob.Constraints.cons2 = x(1) - x(2) + x(3) >= 2;
prob.Constraints.cons3 = 3*x(1) - x(2) - 2*x(3) == -5;
[sol,fval] = solve(prob)
Alan Weiss
MATLAB mathematical toolbox documentation
  1 件のコメント
Mohamed Rashad
Mohamed Rashad 2021 年 8 月 16 日
Thank you Alan.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by