24.03.2013 Views

Linear Programming Lecture Notes - Penn State Personal Web Server

Linear Programming Lecture Notes - Penn State Personal Web Server

Linear Programming Lecture Notes - Penn State Personal Web Server

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

This is not in a form Matlab likes, so we change it by multiplying the constraints by −1<br />

on both sides to obtain:<br />

⎧<br />

min x1 + 1.5x2<br />

⎪⎨ s.t. − 2x1 − 3x2 ≤ −20<br />

⎪⎩<br />

− x1 − 2x2 ≤ −12<br />

x1, x2 ≥ 0<br />

Then we have:<br />

<br />

1<br />

c =<br />

1.5<br />

<br />

−2 −3<br />

A =<br />

−1 −2<br />

<br />

−20<br />

b =<br />

−12<br />

H = r = []<br />

<br />

0<br />

l = u = []<br />

0<br />

The Matlab code to solve this problem is shown in Figure 3.2 The solution Matlab returns in<br />

%%Solve the Diet <strong>Linear</strong> <strong>Programming</strong> Problem<br />

c = [1 1.5]’;<br />

A = [[-2 -3];...<br />

[-1 -2]];<br />

b = [-20 -12]’;<br />

H = [];<br />

r = [];<br />

l = [0 0]’;<br />

u = [];<br />

[x obj] = linprog(c,A,b,H,r,l,u);<br />

Figure 3.2. Matlab input for solving the diet problem. Note that we are solving<br />

a minimization problem. Matlab assumes all problems are mnimization problems,<br />

so we don’t need to multiply the objective by −1 like we would if we started with a<br />

maximization problem.<br />

the x variable is x1 = 3.7184 and x2 = 4.1877, note this is on the line of alternative optimal<br />

solutions, but it is not at either end of the line. I prefer to have a little less ice cream, so I’d<br />

rather have the alternative optimal solution x1 = x2 = 4.<br />

Exercise 39. In previous example, you could also have just used the problem in standard<br />

form with the surplus variables and had A = b = [] and defined H and r instead. Use Matlab<br />

to solve the diet problem in standard form. Compare your results to Example 3.49<br />

50

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!