linprog ouputting all zeros as solution in optimization problem
Ältere Kommentare anzeigen
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)
Antworten (1)
Dyuman Joshi
am 9 Nov. 2023
Bearbeitet: Dyuman Joshi
am 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
Kategorien
Mehr zu Solver Outputs and Iterative Display finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!