3 variable Linear function problem
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Mohamed Rashad
le 12 Août 2021
Commenté : Mohamed Rashad
le 16 Août 2021
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 commentaires
Réponse acceptée
Alan Weiss
le 15 Août 2021
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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Solver Outputs and Iterative Display dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!