Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
1. (P. 15.1 Chapra1) A company makes two types of products, A and B. These products are
produced during a 40-hour work week and then shipped out at the end of the week. They require
20 and 5 kg of raw material per kg of product, respectively, and the company has access to
10,000 kg of raw material per week. Only one product can be created at a time with a production
times for each of 0.05 and 0.15 hrs, respectively. The plant can only store 550 kg of total
product per week. Finally, the company makes profits of $45 and $30 on each unit of A and B,
respectively.
(a) Set up the linear programming problem to maximize profit.
(b) Solve the linear programming problem graphically.
(c) Solve the linear programming problem with the simplex method.
(d) Solve the linear programming problem with Matlab.
Solution
(a) Set up the linear programming problem to maximize profit.
P 45x a 30 x b
(b) To solve graphically, the constraints can be reformulated as the following straight lines
x b (1 / 30) P 15
. xa
1
Chapra and Canale, Numerical Methods for Engineers , Mc-Graw Hill, 4 th Edition, 2002
The constraint lines can be plotted on the xb-xa plane to define the feasible space. Then the
objective function line can be superimposed for various values of P until it reaches the
boundary. The result is P 23700 with xa 483 and xb 67. Notice also that material and
storage are the binding constraints and that there is some slack in the time constraint.
xb
st
materi
P=
or
P=
300
a
ge
tim
237
e
150
al
0
0
0
0
200
optimum
P=
100
500
0
xa
0
0 200 400 600
(c) The simplex tableau for the problem can be set up and solved as
Subject to
The arguments for the Matlab command X=LINPROG(f, A, b, Aeq, beq, LB, UB) are given as
45 20 5 1 0 0 10000 0
30 .05 .15 0 1 0 40 0
f = 0 , A = 0, b = 0, Aeq = 1 1 0 0 1 , beq = 550 , LB = 0 , UB =
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0
0
--------------------------------------------------------------------
% Set 4, Problem 1
f=[-45;-30;0;0;0];
A=zeros(5,5);
b=zeros(5,1);
Aeq=[20 5 1 0 0 ;0.05 0.15 0 1 0;1 1 0 0 1;0 0 0 0 0;0 0 0 0 0];
beq=[10000;40;550;0;0];
LB=[0;0;0;0;0];UB=[inf;inf;inf;inf;inf];
x=linprog(f,A,b,Aeq,beq,LB,UB)
>> s4p1
Optimization terminated successfully.
x=
483.3333
66.6667
0.0000
5.8333
0.0000
------------------------------------------------------
The solution from the Matlab program is
xa = 483.3333
x2 = 66.6667
S1 = 0
S2 = 5.8333
S3 = 0
2. (P. 15.2 Chapra)
A gas processing plant receives a fixed amount of raw gas each week. The raw gas is processed
into three grades of heating gas, regular, premium, and supreme quality. Their production
involves both time and on-site storage constraints. For example, only one of the grades can be
produced at a time, and the facility is open for only 80 hrs/week. There is limited on-site storage
for each of the products. All these factors are listed in Table 4-1 with a metric ton denoted tonne
equal to 1000 kg.
Table 4-1
Product
Resource Regular Premium Supreme Availability
3 3 3
Raw gas 7 m /tonne 11 m /tonne 15 m /tonne 154 m3/week
Production time 10 hr/tonne 8 hr/tonne 12 hr/tonne 80 hr/week
Storage 9 tonnes 6 tonnes 5 tonnes
Profit 150/tonne 175/tonne 250/tonne
(a) Set up the linear programming problem to maximize profit.
(b) Solve the linear programming problem with the simplex method.
(c) Solve the linear programming problem with Matlab.
Solution
(a) Set up the linear programming problem to maximize profit.
subject to
x1 , x 2 , x 3 0 {Positivity constraints}
(b) The simplex tableau for the problem can be set up and solved as
Basis P x1 x2 x3 S1 S2 S3 S4 S5 Solution
P 1 58.3333 0 0 0 20.83 0 8.33 0 1716.7
S1 0 -5.5 0 0 1 -1.25 0 -1 0 48
x2 0 0 1 0 0 0 0 1 0 6
S3 0 1 0 0 0 0 1 0 0 9
S5 0 -0.8333 0 0 0 -0.083 0 0.67 1 2.3333
x3 0 0.83333 0 1 0 0.083 0 -0.67 0 2.6667
x1 , x 2 , x 3 0 {Positivity constraints}
150
175
f=
250
7 11 15
10 12
A=
8
0 0 0
Since there are no equality constraints in this example, Aeq and beq are zeros.
0 9
0 6
LB = and UB =
0
5
The following Matlab statements are used to solve this linear programming problem.
% Set 4, Problem 2
f=[-150;-175;-250];
A=[7 11 15;10 8 12;0 0 0];
b=[154;80;0];
Aeq=zeros(3,3);
beq=zeros(3,1);
LB=[0;0;0];UB=[9;6;5];
x=linprog(f,A,b,Aeq,beq,LB,UB)
>> s4p2
Optimization terminated successfully.
x=
0.0000
6.0000
2.6667
-------------------------------------------------------------------------------------------------------------
The solution from the Matlab program is
x1 = 0
x2 = 6
x3 = 2.6667
3. (P. 15.3 Chapra)
Consider the linear programming problem:
5
Maximize f(x, y) = x + y, subject to
3
x + 2.5y 15
x+y7
2x + y 9
x 0 and y 0
(a) Solve the linear programming problem graphically.
(b) Solve the linear programming problem with the simplex method.
(c) Solve the linear programming problem with Matlab.
Solution
To solve graphically, the constraints can be reformulated as the following straight lines
y = 6 0.4x
y=7x
y = 9 2x
y = 9 - 2x
E
5 D
C
y = 6 - 0 .4 x
y = 7 - x
A B
0 5 10
(b) Solve the linear programming problem with the simplex method.
5
Maximize f(x, y) = x + y, subject to
3
x + 2.5y + S1 = 15
x + y + S2 = 7
2x + y + S3 = 9
x, y, S1, S2, S3 0
at A, x = 0 y=0
S1 = 15, S2 = 7, S3 = 9, and f(x, y) = 0
at B, y = 0 S3 = 0
x + S1 = 15
x + S2 = 7
2x = 9
x = 4.5, S1 = 10.5, S2 = 2.5, and f(x, y) = 7.5
at C, S3 = 0 S2 = 0
x + 2.5y + S1 = 15
x+y= 7
2x + y = 9
x = 2, y = 0, S1 = 0.5, and f(x, y) = 8.33
(c) Solve the linear programming problem with Matlab.
5
Minimize y = x y
3
x + 2.5y + S = 15
x+y7
2x + y 9
x, y, and S 0
5 / 3
1
f=
0
1 1 0
2 0
A=
1
0 0 0
7
9
b=
0
1 1 1 15
0 0 0
Aeq =
0
and beq =
0 0 0
0
0
0
LB = and UB =
0
The following Matlab statements are used to solve this linear programming problem.
>> s4p3
Optimization terminated successfully.
x=
2.0000
5.0000
0.5000
-------------------------------------------------------------------------------------------------------------
The solution from the Matlab program is
x1 = 2
x2 = 5
S = 0.5
4. (P. 13.7 Chapra) Employ the following methods to find the maximum of
Solution
% Set 4, problem 4
fx = '2*x - 1.75*x^2 + 1.1*x^3 - 0.25*x^4';
x0 = 1.75; x = x0; f0 = eval(fx);
x1 = 2; x = x1; f1 = eval(fx);
x2 = 2.25; x = x2; f2 = eval(fx);
f3save=f0;
disp('Quadratic interpolation')
for i=1:5
top = f0*(x1*x1-x2*x2)+f1*(x2*x2-x0*x0)+f2*(x0*x0-x1*x1);
bot = 2*f0*(x1-x2)+2*f1*(x2-x0)+2*f2*(x0-x1);
x3 = top/bot;
x = x3; f3 = eval(fx);
fprintf('x3 = %10.5f, f(x3) = %10.5f\n',x,f3)
% if abs(f3save-f3)<.00001, break, end
f3save=f3;
if x3<x0
x0=x3;x2=x1;x1=x0;
f0=f3;f2=f1;f1=f0;
elseif x3<x1
x2=x1;x1=x3;
f2=f1;f1=f3;
elseif x3<x2
x0=x1;x1=x3;
f0=f1;f1=f3;
else
x0=x1;x1=x2;x2=x3;
f0=f1;f1=f2;f2=f3;
end
end
disp('Newton method')
x = 2.5;
for i=1:10
fx = 2*x - 1.75*x^2 + 1.1*x^3 - 0.25*x^4;
fprintf('x = %8.5f, f(x) = %8.5f\n',x, fx)
dx = (2 - 3.5*x + 3.3*x^2 - x^3)/(- 3.5 + 6.6*x - 3*x^2 );
x= x - dx;
if abs(dx)<0.01, break, end
end
fx = 2*x - 1.75*x^2 + 1.1*x^3 - 0.25*x^4;
fprintf('x = %8.5f, f(x) = %8.5f\n',x, fx)
>> s4p4
Quadratic interpolation
x3 = 2.06166, f(x3) = 1.80775
x3 = 2.07412, f(x3) = 1.80813
x3 = 2.07807, f(x3) = 1.80817
x3 = 2.07898, f(x3) = 1.80817
x3 = 2.07926, f(x3) = 1.80817
Newton method
x = 2.50000, f(x) = 1.48438
x = 2.19565, f(x) = 1.78800
x = 2.09170, f(x) = 1.80796
x = 2.07951, f(x) = 1.80817
x = 2.07935, f(x) = 1.80817
5. (P. 13.9 Chapra) Employ the following methods to find the optimum of
Solution
% Set 4, problem 5
fx = '6*x + 7.5*x^2 + 3*x^3 + x^4';
x0 = -2; x = x0; f0 = eval(fx);
x1 = -12; x = x1; f1 = eval(fx);
x2 = 1; x = x2; f2 = eval(fx);
f3save=f0;
disp('Quadratic interpolation')
for i=1:5
top = f0*(x1*x1-x2*x2)+f1*(x2*x2-x0*x0)+f2*(x0*x0-x1*x1);
bot = 2*f0*(x1-x2)+2*f1*(x2-x0)+2*f2*(x0-x1);
x3 = top/bot;
x = x3; f3 = eval(fx);
fprintf('x3 = %10.5f, f(x3) = %10.5f\n',x,f3)
% if abs(f3save-f3)<.00001, break, end
f3save=f3;
if x3<x0
x0=x3;x2=x1;x1=x0;
f0=f3;f2=f1;f1=f0;
elseif x3<x1
x2=x1;x1=x3;
f2=f1;f1=f3;
elseif x3<x2
x0=x1;x1=x3;
f0=f1;f1=f3;
else
x0=x1;x1=x2;x2=x3;
f0=f1;f1=f2;f2=f3;
end
end
disp('Newton method')
x = -1;
for i=1:10
fx = 6*x + 7.5*x^2 + 3*x^3 + x^4;
fprintf('x = %8.5f, f(x) = %8.5f\n',x, fx)
dx = (6 + 15*x + 9*x^2 + 4*x^3)/(15 + 18*x + 12*x^2);
x= x - dx;
if abs(dx)<0.01, break, end
end
fx = 6*x + 7.5*x^2 + 3*x^3 + x^4;
fprintf('x = %8.5f, f(x) = %8.5f\n',x, fx)
>> s4p5
Quadratic interpolation
x3 = -0.50980, f(x3) = -1.43952
x3 = 0.18902, f(x3) = 1.42358
x3 = -0.35706, f(x3) = -1.30649
x3 = -0.50715, f(x3) = -1.43906
x3 = -0.52720, f(x3) = -1.44099
Newton method
x = -1.00000, f(x) = -0.50000
x = -0.55556, f(x) = -1.43766
x = -0.52782, f(x) = -1.44099
x = -0.52803, f(x) = -1.44099
6. Minimize the function f(x, y) = 4x2 + y2 2xy, using Newton method with x0 = [1 1]T.
Solution
8 x 2 y
f(x i) = 2 y 2 x
8 2
Hi =
2 2
Hix i = f(x i)
6 8 2 x 6
For i = 0, f(x i) = 0 2
2 y = 0
x = 1, y = 1
x1 = x0 + x = 1 1 = 0
y1 = y0 + y = 1 1 = 0