% Max Z=3x_1+5x_2 <-> Min F=-3x_1-5x_2
% sub. to. Ax<=b, x>=0, where Ax<=b in components: x_1<=4; 2x_2<=12;3x_1+2x_2<=18; and x_1>=0,x_2>=0
%
%

% code the coefficient of F:
f = [-3; -5]; % Change it to minimization which is Matlab's default setting.
% code the matrix A: 
A =  [1 0
      0 2
      3 2];
% code the vector b (in column):
b = [4; 12; 18];
% and the lower bound of x:
lb = zeros(2,1);

%Next, call a linear programming routine.

options = optimset('LargeScale','off','Simplex','on','Display','iter');

[x,fval,exitflag,output,lambda] = linprog(f,A,b,[],[],lb,[],[],options);

% to view the result
x 

% the optimal minimum
fval

% the resource b's shadow price 
lambda.ineqlin 

% and the lower bound shadow price
lambda.lower 


return
%%
% Linear Programming method to find NE
%

%A=[[-1 0]; [1 -2]];
A=[[-2 2]; [4 -3]];
offset=min(min(A));
AA=A-offset;

[r,c]=size(AA);

f=zeros(r+1,1);
f(end)=1;

rone=ones(r,1);
GA=[AA -rone];

b=zeros(r,1);

Aeq=1-f';
beq=1;

lb=0*b;

%options = optimset('LargeScale','off','Simplex','on','Display','iter');
options = optimset('LargeScale','off','Simplex','on');

[optsolu,fval,exitflag,output,lambda] = ...
    linprog(f,GA,b,Aeq,beq,lb,[],[],options);
shadow_price_inequalities=lambda.ineqlin;
