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

Answers (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

Asked:

on 9 Nov 2023

Edited:

on 12 Nov 2023

Community Treasure Hunt

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

Start Hunting!