2015年10月26日星期一

Plot the feasible region for linear programming problems in Matlab

Keywords: ME558, Assignment, Integer Programming, branch and bound algorithm

Scenario:

When working on linear programming problems with graphical methods, a 2D plot with feasible region labeled is always recommended. Following are two ways to plot a LP problem in Matlab with feasible region labeled.

Method 1: MuPad

1. Type 'mupad' in the command window to open the MuPad and create a new file.

2. Input the integer problems in the following sample format and press ENTER
k := [{x-y>=-4, 4*x+5*y<=45,5*x-2*y<=20,5*x+2*y>=10,x>=0,y>=-4}, x-4*y]:
g := linopt::plot_data(k, [x, y]):
plot(g):


Note that the default objective is to maximize the x-4y. Transforms are needed for a minimize type problem.
3. A graph is generated as following.
4. You can check the coordinates of the points on the graph by long-clicking the points on the plot. 

Method 2: Matlab Function
An open source function called plot_feasible.m which is available in Matlab Central also serves the same function. 


This function not only plots the graphical expression, but also gives optimized solutions for the given problem using some solver. 
The inputs of the function are A,b,c matrix. Detailed manuals are in the comment of the code. 
A sample outcome is as following