linprog ouputting all zeros as solution in optimization problem
Afficher commentaires plus anciens
I am trying to solve the following optimization problem (view first lines for the objective function and constraints), and I am getting all zeros as my solution. How can I modify my code to output a non-zero solution? I have tried setting a lower bound, and I left the upper bound empty.
%max𝑍=3*𝑥1+5*x2+6*x3
%s.t. 2𝑥1+𝑥2+𝑥3≤4
% 𝑥1+2𝑥2+𝑥3≤4
% x1+𝑥2+2𝑥3≤4
% 𝑥1+𝑥2+𝑥3≤3
% x1,𝑥2,𝑥3≥0
A = [2 1 1
1 2 1
1 1 2
1 1 1];
b = [4 4 4 3];
%set Aeq and Beq
Aeq = [];
beq = [];
% objective function
%Z = 3*𝑥1+5*x2+6*x3
f = [3 5 6];
%set bounds
%ub = [];
lb = [0,0,0];
[x,fval] = linprog(f,A,b,Aeq,beq,lb)
Réponses (1)
Dyuman Joshi
le 9 Nov 2023
Modifié(e) : Dyuman Joshi
le 9 Nov 2023
linprog finds the minimum of the problem specified.
To find the maximum, minimize the negative of the objective funciton -
%max𝑍=3*𝑥1+5*x2+6*x3
%s.t. 2𝑥1+𝑥2+𝑥3≤4
% 𝑥1+2𝑥2+𝑥3≤4
% x1+𝑥2+2𝑥3≤4
% 𝑥1+𝑥2+𝑥3≤3
% x1,𝑥2,𝑥3≥0
A = [2 1 1
1 2 1
1 1 2
1 1 1];
b = [4 4 4 3];
%set Aeq and Beq
Aeq = [];
beq = [];
% objective function
%Z = 3*𝑥1+5*x2+6*x3
f = [3 5 6];
%set bounds
ub = [];
lb = [0,0,0];
% vv
[x,fminval] = linprog(-f,A,b,Aeq,beq,lb,ub)
fmaxval = -fminval
Catégories
En savoir plus sur Solver Outputs and Iterative Display dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!