Professional Documents
Culture Documents
J. Kizito
Makerere University
e-mail: john.kizito@mak.ac.ug
www: https://www.socnetsolutions.com/~jona
materials: https://www.socnetsolutions.com/~jona/materials/MTH3107
e-learning environment: http://muele.mak.ac.ug
office: block A, level 3, department of computer science
alt. office: institute of open, distance, and eLearning
1 Syntax
2 Arguments
3 Examples
4 Conclusion
Syntax
Recall: Matrix Notation
Syntax
Recall: Matrix Notation
Syntax
Recall: Matrix Notation
Syntax
Recall: Matrix Notation
Syntax
Input Arguments
rx, fval, exitflag , output, lambdas linprog pf , A, b, Aeq, beq, lb, up, x0, options q
f Linear objective function vector
A or Aineq: Matrix for linear inequality constraints
b or bineq: Vector for linear inequality constraints
Aeq Matrix for linear equality constraints
beq Vector for linear equality constraints
lb Vector of lower bounds
ub Vector of upper bounds
x0 Initial point for x, active set algorithm only
solver ’linprog’
options Optimization options used by linprog. Some options apply
to all algorithms, and others are only relevant when using the
large-scale algorithm
Example
Example
Example
Example
Example
Example 1 Solution
maximize 3x1 2x2
subject to x 3
2
, fval 13, exitflag 1
4x1 2x2 ¤ 16
x1 2x2 ¤ 8
x1 x2 ¤ 5
Note that we obtain the same solution
x1 ¥ 0; x2 ¥ 0
to this problem as we did when using
the Simplex Method
linprog solves linear programming
In MATLAB minimization problems
¡ f = [-3 -2] For maximization problems, we
¡ A = [4 2; 1 2; 1 1] multiply the objective function by 1.
¡ b = [16; 8; 5] Consequently, the same will apply to
¡ lb = zeros(2,1) fval
¡ [x,fval,exitflag] = i.e., fval 13 for the maximization
linprog(f,A,b,[],[],lb) problem above
Kizito (Makerere University) MTH 3107 Feb, 2022 7 / 13
Examples
Example
Example 1 Solution
maximize 3x1 2x2
subject to x 3
2
, fval 13, exitflag 1
4x1 2x2 ¤ 16
x1 2x2 ¤ 8
x1 x2 ¤ 5
Note that we obtain the same solution
x1 ¥ 0; x2 ¥ 0
to this problem as we did when using
the Simplex Method
linprog solves linear programming
In MATLAB minimization problems
¡ f = [-3 -2] For maximization problems, we
¡ A = [4 2; 1 2; 1 1] multiply the objective function by 1.
¡ b = [16; 8; 5] Consequently, the same will apply to
¡ lb = zeros(2,1) fval
¡ [x,fval,exitflag] = i.e., fval 13 for the maximization
linprog(f,A,b,[],[],lb) problem above
Kizito (Makerere University) MTH 3107 Feb, 2022 7 / 13
Examples
Example
Example 1 Solution
maximize 3x1 2x2
subject to x 3
2
, fval 13, exitflag 1
4x1 2x2 ¤ 16
x1 2x2 ¤ 8
x1 x2 ¤ 5
Note that we obtain the same solution
x1 ¥ 0; x2 ¥ 0
to this problem as we did when using
the Simplex Method
linprog solves linear programming
In MATLAB minimization problems
¡ f = [-3 -2] For maximization problems, we
¡ A = [4 2; 1 2; 1 1] multiply the objective function by 1.
¡ b = [16; 8; 5] Consequently, the same will apply to
¡ lb = zeros(2,1) fval
¡ [x,fval,exitflag] = i.e., fval 13 for the maximization
linprog(f,A,b,[],[],lb) problem above
Kizito (Makerere University) MTH 3107 Feb, 2022 7 / 13
Examples
Example
Example 1 Solution
maximize 3x1 2x2
subject to x 3
2
, fval 13, exitflag 1
4x1 2x2 ¤ 16
x1 2x2 ¤ 8
x1 x2 ¤ 5
Note that we obtain the same solution
x1 ¥ 0; x2 ¥ 0
to this problem as we did when using
the Simplex Method
linprog solves linear programming
In MATLAB minimization problems
¡ f = [-3 -2] For maximization problems, we
¡ A = [4 2; 1 2; 1 1] multiply the objective function by 1.
¡ b = [16; 8; 5] Consequently, the same will apply to
¡ lb = zeros(2,1) fval
¡ [x,fval,exitflag] = i.e., fval 13 for the maximization
linprog(f,A,b,[],[],lb) problem above
Kizito (Makerere University) MTH 3107 Feb, 2022 7 / 13
Examples
Formulation Examples
Example 3
Problem
You need to buy some filing cabinets. You know that Cabinet X costs $10 per unit,
requires six square feet of floor space, and holds eight cubic feet of files. Cabinet Y
costs $20 per unit, requires eight square feet of floor space, and holds twelve cubic feet
of files. You have been given $140 for this purchase, though you don’t have to spend
that much. The office has room for no more than 72 square feet of cabinets. How many
of which model should you buy, in order to maximize storage volume?
Formulation
1 Let x be the number of model X cabinets purchased,
y the number of model Y cabinets purchased
2 Cost: 10x 20y ¤ 140
Space: 6x 8y ¤ 72
3 Volume: 8x 12y
4 Write as a dictionary
Formulation Examples
Example 3
Problem
You need to buy some filing cabinets. You know that Cabinet X costs $10 per unit,
requires six square feet of floor space, and holds eight cubic feet of files. Cabinet Y
costs $20 per unit, requires eight square feet of floor space, and holds twelve cubic feet
of files. You have been given $140 for this purchase, though you don’t have to spend
that much. The office has room for no more than 72 square feet of cabinets. How many
of which model should you buy, in order to maximize storage volume?
Formulation
1 Let x be the number of model X cabinets purchased,
y the number of model Y cabinets purchased
2 Cost: 10x 20y ¤ 140
Space: 6x 8y ¤ 72
3 Volume: 8x 12y
4 Write as a dictionary
Formulation Examples
Example 4
Problem
A school is preparing a trip for 400 students. The company which is providing the
transportation has 10 buses of 50 seats each and 8 buses of 40 seats, but only has 9
drivers available. The rental cost for a large bus is $800 and $600 for the small bus.
Calculate how many buses of each type should be used for the trip for the least possible
cost
Formulation
1 Let x be the number of small buses, y the number of big buses
2 minimize 600x 800y
subject to
40x 50y ¥ 400
x1 2x2 ¤ 8
x y ¤9
x ¥ 0; y ¥ 0
Formulation Examples
Example 4
Problem
A school is preparing a trip for 400 students. The company which is providing the
transportation has 10 buses of 50 seats each and 8 buses of 40 seats, but only has 9
drivers available. The rental cost for a large bus is $800 and $600 for the small bus.
Calculate how many buses of each type should be used for the trip for the least possible
cost
Formulation
1 Let x be the number of small buses, y the number of big buses
2 minimize 600x 800y
subject to
40x 50y ¥ 400
x1 2x2 ¤ 8
x y ¤9
x ¥ 0; y ¥ 0
Formulation Examples
Example 5 – Problem
A cargo plane has three compartments for storing cargo: front, center and rear. These
compartments have the following limits on both weight and space:
Furthermore, the weight of the cargo in the respective compartments must be the same
proportion of that compartments weight capacity to maintain the balance of the plane. The
following four cargoes are available for shipment on the next flight:
Any proportion of these cargoes can be accepted. The objective is to determine how much (if
any) of each cargo C1, C2, C3 and C4 should be accepted and how to distribute each among
the compartments so that the total profit for the flight is maximized.
Kizito (Makerere University) MTH 3107 Feb, 2022 10 / 13
Examples
Formulation Examples
Example 5 – Formulation
1 Let xij : the number of tonnes of cargo i that is put into compartment j where
xij ¥ 0 for i 1, 2, 3, 4; j 1, 2, 3 (Front, Centre, Rear)
Formulation Examples
Example 5 – The Dictionary
maximize
310px11 x12 x13 q 380px21 x22 x23 q 350px31 x32 x33 q 285px41 x42 x43 q
subject to
x11 x12 x13 ¤ 18
x21 x22 x23 ¤ 15
x31 x32 x33 ¤ 23
x41 x42 x43 ¤ 12
x11 x21 x31 x41 ¤ 10
x12 x22 x32 x42 ¤ 16
x13 x23 x33 x43 ¤ 8
480x11 650x21 580x31 390x41 ¤ 6800
480x12 650x22 580x32 390x42 ¤ 8700
480x13 650x23 580x33 390x43 ¤ 5300
16x11 16x21 16x31 16x41 10x12 10x22 10x32 10x42 0
8x12 8x22 8x32 8x42 16x13 16x23 16x33 16x43 0
Example 5
Conclusion