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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Solver 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