3 variable Linear function problem

7 visualizaciones (últimos 30 días)
Mohamed Rashad
Mohamed Rashad el 12 de Ag. de 2021
Comentada: Mohamed Rashad el 16 de Ag. de 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

Respuesta aceptada

Alan Weiss
Alan Weiss el 15 de Ag. de 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

Más respuestas (0)

Categorías

Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by