linprog ouputting all zeros as solution in optimization problem
显示 更早的评论
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)
回答(1 个)
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
类别
在 帮助中心 和 File Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!