simple linear programming problem
3 views (last 30 days)
Show older comments
Ricardo Machado
on 20 Sep 2019
Commented: Steven Lord
on 20 Sep 2019
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?
0 Comments
Accepted Answer
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
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.
More Answers (0)
See Also
Categories
Find more on Linear Programming and Mixed-Integer Linear Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!