simple linear programming problem

4 views (last 30 days)
This is an example from my textbook
Minimize 5x-7y-4z+6t
Subject to 2x+6y+z-t <= 5
5x+3y-6z-2t <= 7
-x-3y+6z+2t <= 6
x,y,z,t > = 0
So this is my code
f = [5 -7 -4 6]
A = [2 6 1 -1
5 3 -6 -2
-1 -3 6 2]
B = [5 7 6]
x = linprog(f,A,B)
So do i have to list the linear equality constraint if all variables are greater than zero or is there something wrong with the code?

Accepted Answer

Fabio Freschi
Fabio Freschi on 20 Sep 2019
% your code
f = [5 -7 -4 6]
A = [2 6 1 -1
5 3 -6 -2
-1 -3 6 2]
B = [5 7 6]
% add lowerbound (0) and upper bound (Inf)
lb = [0 0 0 0]
ub = [Inf Inf Inf Inf]
% solve (Aeq = []; beq = [];)
x = linprog(f,A,B,[],[],lb,ub)
  1 Comment
Steven Lord
Steven Lord on 20 Sep 2019
Fabio Freschi is correct. If you look at the description of the lb and ub input arguments on the linprog documentation page you'll see it says "Set Aeq = [] and beq = [] if no equalities exist."
The "Obtain Solution and Lagrange Multipliers" example on that page demonstrates this, solving a problem with bounds (actually, just lower bounds but no upper bounds) but no equality constraints.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!