Sei sulla pagina 1di 16

EGR 599 Advanced Engineering Math II _____________________

LAST NAME, FIRST


Problem set #4

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.

Define xa = amount of product A produced, and xb = amount of product B produced. The


objective function is to maximize profit,

P  45x a  30 x b

Subject to the following constraints

20 x a  5x b  10000 {raw materials}


0.05x a  0.15x b  40 {production time}
x a  xb  550 {storage}
x a , xb  0 {positivity}

(b) To solve graphically, the constraints can be reformulated as the following straight lines

x b  2000  4 x a {raw materials}


x b  266.667  0.3333 x a {production time}
x b  550  x a {storage}

The objective function can be reformulated as

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

Basis P xa xb S1 S2 S3 Solution Intercept


P 1 -45 -30 0 0 0 0
material S1 0 20 5 1 0 0 10000 500
time S2 0 0.05 0.15 0 1 0 40 800
storage S3 0 1 1 0 0 1 550 550

Basis P xa xb S1 S2 S3 Solution Intercept


P 1 0 -18.75 2.25 0 0 22500
xa xa 0 1 0.25 0.05 0 0 500 2000
time S2 0 0 0.1375 -0 1 0 15 109.0909
storage S3 0 0 0.75 -0.05 0 1 50 66.66667

Basis P xa xb S1 S2 S3 Solution Intercept


P 1 0 0 1 0 25 23750
xa xa 0 1 0 0.067 0 -0.333 483.33333
time S2 0 0 0 0.007 1 -0.183 5.8333333
xb xb 0 0 1 -0.07 0 1.333 66.666667

(d) Solve the linear programming problem with Matlab.

The problem is reformulated using slack variable S1, S2, and S3

Minimize y =  45xa  30xb

Subject to

20xa + 5xb + S1 = 10000


0.05xa + 0.15xb + S2 = 40
xa + xb + S3 = 550
xa, xb, S1, S2, and S3  0

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.

The total LP formulation is given by

Maximize Z  150 x1  175x 2  250 x 3 {Maximize profit}

subject to

7 x1  11x 2  15x 3  154 {Material constraint}


10 x1  8 x 2  12 x 3  80 {Time constraint}
x1  9 {“Regular” storage constraint}
x2  6 {“Premium” storage constraint}
x3  5 {“Supreme” storage constraint}

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 Intercept


P 1 -150 -175 -250 0 0 0 0 0 0
S1 0 7 11 15 1 0 0 0 0 154 10.2667
S2 0 10 8 12 0 1 0 0 0 80 6.66667
S3 0 1 0 0 0 0 1 0 0 9 
S4 0 0 1 0 0 0 0 1 0 6 
S5 0 0 0 1 0 0 0 0 1 5 5

Basis P x1 x2 x3 S1 S2 S3 S4 S5 Solution Intercept


P 1 -150 -175 0 0 0 0 0 250 1250
S1 0 7 11 0 1 0 0 0 -15 79 7.18182
S2 0 10 8 0 0 1 0 0 -12 20 2.5
S3 0 1 0 0 0 0 1 0 0 9 
S4 0 0 1 0 0 0 0 1 0 6 6
x3 0 0 0 1 0 0 0 0 1 5 

Basis P x1 x2 x3 S1 S2 S3 S4 S5 Solution Intercept


P 1 68.75 0 0 0 21.88 0 0 -12.5 1687.5
S1 0 -6.75 0 0 1 -1.375 0 0 1.5 51.5 34.3333
x2 0 1.25 1 0 0 0.125 0 0 -1.5 2.5 -1.66667
S3 0 1 0 0 0 0 1 0 0 9 
S4 0 -1.25 0 0 0 -0.125 0 1 1.5 3.5 2.33333
x3 0 0 0 1 0 0 0 0 1 5 5

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

(c) Solve the linear programming problem with Matlab.

The problem is reformulated as

Minimize y =  150 x1  175 x2  250 x3


7 x1  11x 2  15x 3  154 {Material constraint}
10 x1  8 x 2  12 x 3  80 {Time constraint}
x1  9 {“Regular” storage constraint}
x2  6 {“Premium” storage constraint}
x3  5 {“Supreme” storage constraint}

x1 , x 2 , x 3  0 {Positivity constraints}

We use the Matlab command X=LINPROG(f, A, b, Aeq, beq, LB, UB)

The coefficient vector f for the objective function is

  150 
  175 
f=  
  250

The matrix coefficient A for the inequality constraints is

7 11 15
10 12
A= 
8


0 0 0

The right hand vector b for the inequality constraints is


154 
 80 
b=  

 0 

Since there are no equality constraints in this example, Aeq and beq are zeros.

Aeq = 0 and beq = 0

The lower and upper bounds vectors are given by

0  9 
0  6
LB =   and UB =  

0 
 
 5

The following Matlab statements are used to solve this linear programming problem.

Matlab Program -----------------------------------------------------

% 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+y7
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

(a) Solve the linear programming problem graphically.

To solve graphically, the constraints can be reformulated as the following straight lines

y = 6  0.4x

y=7x

y = 9  2x

The objective function can be reformulated as


5
y= x +f(x, y)
3
The constraint lines can be plotted on the x-y plane to define the feasible space. Then the
objective function line can be superimposed for various values of f(x, y) until it reaches the
boundary. The result is f(x, y)  8.33 with x = 23 and y = 5.
10

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.

The problem is reformulated as

5
Minimize y =  x y
3
x + 2.5y + S = 15
x+y7
2x + y  9
x, y, and S  0

We use the Matlab command X=LINPROG(f, A, b, Aeq, beq, LB, UB).

The coefficient vector f for the objective function is

  5 / 3
 1 
f=  
 0 

The matrix coefficient A for the inequality constraints is

1 1 0
2 0
A= 
1


0 0 0

The right hand vector b for the inequality constraints is

7 
9 
b=  

0

The equality constraints Aeq and beq are given as

1 1 1 15
0 0 0
Aeq = 
0
 and beq =  

0 0 0
 
0

The lower and upper bounds vectors are given by

0   
0   
LB =   and UB =  
 
 
0 
 

The following Matlab statements are used to solve this linear programming problem.

Matlab Program -----------------------------------------------------


% Set 4, Problem 3
f=[-5/3;-1;0];
A=[1 1 0;2 1 0;0 0 0];
b=[7;9;0];
Aeq=[1 2.5 1; 0 0 0;0 0 0];
beq=[15;0;0];
LB=[0;0;0];UB=[inf;inf;inf];
x=linprog(f,A,b,Aeq,beq,LB,UB)

>> 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

f(x) = 2x  1.75x2 + 1.1x3  0.25x4

a) Quadratic interpolation (x0 = 1.75, x1 = 2, x2 = 2.25, iterations = 5)


b) Newton method (x0 = 2.5, |xi+1  xi| < 0.01)

Solution

f(x) = 2x  1.75x2 + 1.1x3  0.25x4

f’(x) = 2  3.5x + 3.3x2  x3

f”(x) =  3.5 + 6.6x  3x2

% 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

f(x) = 6x + 7.5x2 + 3x3 + x4

a) Quadratic interpolation (x0 =  2, x1 =  1, x2 = 1, iterations = 5)


b) Newton method (x0 =  1, |xi+1  xi| < 0.01)

Solution

f(x) = 6x + 7.5x2 + 3x3 + x4

f’(x) = 6 + 15x + 9x2 + 4x3

f”(x) = 15 + 18x + 12x2

% 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

x i+1 = x i  Hi-1f(x i) (1)

8 x  2 y 
f(x i) = 2 y  2 x 
 

 8  2
Hi = 
 2 2 

Let x i = x i+1  x i, equation (1) becomes

Hix 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

f(x = 0, y = 0) = 0 is the solution

Potrebbero piacerti anche