%Solves a linear programming problem
 
function ExampleLinprog()

% Suppose that you are asked to find x,y that maximizes the objective function 
% Z(x,y):= 3x + 5y 
% subject to the restrictions (constraint) x<=4, 2y<=12, 3x+2y<=18, 
% x,y>=0
 
% First, enter the coefficients

Z = [3; 5]; 
A = [1 0;  0 2;  3 2]; 
b = [4; 12; 18]; 

% Second, evaluate linprog: 
% X = LINPROG(f,A,b,Aeq,beq,LB,UB) solves the problem above while satisfying the inequality constraints Ax <=b, 
% the equality constraints Aeq*x = beq and define a set of lower and upper bounds on the design variables, x, 
% so that the solution is in the range LB <= X <= UB. If you do not need to specify some constraints, then use [] in the corresponding place.

[X,FVAL]=linprog(-Z,A,b,[],[],[0 0],[]); % Notice that we have used -Z since linprog solves a minimization problem.

% Since our problem does not have equality constraints and there is no upper bound for the vector X, then we have 
% placed [] in each corresponding position.


% Finally print the X, Y which minimizes the objective function z(x,y)
X

%Print the value -FVAL which represent the maximum of our objective
%function Z(x,y) since F val is the minimum of -Z
-FVAL

%End of program
