Presentation is loading. Please wait.

Presentation is loading. Please wait.

Use MATLAB to solve linear programs LI Xiao-lei. MATLAB format for linear programs MATLAB uses the following format for linear programs: min z = f T x.

Similar presentations


Presentation on theme: "Use MATLAB to solve linear programs LI Xiao-lei. MATLAB format for linear programs MATLAB uses the following format for linear programs: min z = f T x."— Presentation transcript:

1 Use MATLAB to solve linear programs LI Xiao-lei

2 MATLAB format for linear programs MATLAB uses the following format for linear programs: min z = f T x s. t. Ax ≤ b A eq = b eq (1) x≥ l x ≤ u

3 Command format A linear program in the format of equation (1) is solved using the command: x = linprog(f,A, b, A eq, b eq, l, u)

4 Simple example Suppose we want to solve the following linear program using MATLAB: max z=4x1 + 2x2 + x3 s. t. 2x1 + x2 ≤ 1 x1 +2x3 ≤ 2 x1 + x2 + x3 = 1 x1 ≤1 x2 ≤ 1 x3 ≤2 x1≥0;x2≥0;x3≥0

5 Simple example Convert the LP into MATLAB format Comparing the above LP with the format given in (1) we get:

6 Simple example Input the variables into MATLAB: >> f = -[4;2;1]; >> A = [2 1 0;1 0 2]; >> b = [1;2]; >> Aeq = [1 1 1]; >> beq = [1]; >> l = [0;0;0]; >> u = [1;1;2];

7 Simple example Solve the linear program using MATLAB: >> x = linprog(f,A,b,Aeq,beq,l,u) And you should see the following: Optimization terminated successfully. x = 0.5000 0.0000 0.5000

8 What to do when some of the variables are missing ? For example, suppose there are no lower bounds on the variables. In this case define l to be the empty set using the MATLAB command: >> l = []; Do this and resolve the LP by calling the linprog command. You should see: Optimization terminated successfully. x = 0.6667 -0.3333 0.6667

9 What to do when some of the variables are missing ? Similarly define other matrices to be empty matrices if they do not appear in the problem. For example, if there are no equality constraints, define Aeq and beq as empty sets, i.e. >> Aeq = []; >> beq = []; So this and resolve the LP by calling linprog. You should see: Optimization terminated successfully. x = 0.0000 1.0000


Download ppt "Use MATLAB to solve linear programs LI Xiao-lei. MATLAB format for linear programs MATLAB uses the following format for linear programs: min z = f T x."

Similar presentations


Ads by Google