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)
Optimal solution found.
x = 3ร—1
0 0 0
fval = 0

๋‹ต๋ณ€ (1๊ฐœ)

Dyuman Joshi
Dyuman Joshi 2023๋…„ 11์›” 9์ผ
ํŽธ์ง‘: Dyuman Joshi 2023๋…„ 11์›” 9์ผ

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)
Optimal solution found.
x = 3ร—1
0 1.3333 1.3333
fminval = -14.6667
fmaxval = -fminval
fmaxval = 14.6667

์นดํ…Œ๊ณ ๋ฆฌ

๋„์›€๋ง ์„ผํ„ฐ ๋ฐ File Exchange์—์„œ Solver Outputs and Iterative Display์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณด๊ธฐ

ํƒœ๊ทธ

์งˆ๋ฌธ:

2023๋…„ 11์›” 9์ผ

ํŽธ์ง‘:

2023๋…„ 11์›” 12์ผ

Community Treasure Hunt

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

Start Hunting!

Translated by