3 variable Linear function problem
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!