MATLAB: lp477
← ChE 477: Process Optimization
close all
clear all
clc
% Linear Programming (LP) Examples
% type "help linprog" for more information
% Ugur Akman 2004
% Example p.98 Tables & Chairs Example
% OBJ: min f(x1,x2) = -7x1 - 5x2
% g1: 4x1 + 3x2 < 240
% g2: 2x1 + x2 < 100
% x1 > 0 & x2 > 0
% Objective fct coefficients
C = [-7 ; -5]
% Inequality constraints' coefficients
% NOTE: You must express inequalities as "g < bineq"
Aineq = [4 3
2 1]
% Inequality constraints' right-hand-sides
% NOTE: You must express inequalities as "g < bineq"
bineq = [240 ; 100]
% Define bounds (only lower bounds of zero for this example)
lb = zeros(2,1)
% Call linprog to solve the problem
[x,fval] = linprog(C,Aineq,bineq,[],[],lb)
% Example p.124 Two-Phase Simplex Example
% OBJ: min f(x1,x2) = 2x1 - x2
% g1: x1 + x2 > 0
% g2: 2x1 + 3x2 < 12
% h1: x1 - 2x2 = 2
% x1 > 0 & x2 > 0
% Objective fct coefficients
C = [2 ; -1]
% Inequality constraints' coefficients
% NOTE: You must express inequalities as "g < bineq"
Aineq = [-1 -1
2 3]
% Inequality constraints' right-hand-sides
% NOTE: You must express inequalities as "g < bineq"
bineq = [-2 ; 12]
% Equality constraints' coefficients
% NOTE: You must express equalities as "h = beq"
Aeq = [1 -2]
% Equality constraints' right-hand-sides
% NOTE: You must express equalities as "h = beq"
beq = [2]
% Define bounds (only lower bounds of zero for this example)
lb = zeros(2,1)
% Call linprog to solve the problem
[x,fval,exitflag,output,lambda] = linprog(C,Aineq,bineq,Aeq,beq,lb)
C =
-7
-5
Aineq =
4 3
2 1
bineq =
240
100
lb =
0
0
Optimization terminated.
x =
30.0000
40.0000
fval =
-410.0000
C =
2
-1
Aineq =
-1 -1
2 3
bineq =
-2
12
Aeq =
1 -2
beq =
2
lb =
0
0
Optimization terminated.
x =
2.0000
0.0000
fval =
4.0000
exitflag =
1
output =
iterations: 5
algorithm: 'large-scale: interior point'
cgiterations: 0
message: 'Optimization terminated.'
lambda =
ineqlin: [2x1 double]
eqlin: -1.2958
upper: [2x1 double]
lower: [2x1 double]
Published with MATLAB® 7.0