%MATLAB code to pivot on a dictionary
%Usage:
%Set up:
%Specify...
%   an mxn matrix, A, of constraint coeffs.
%   an mx1 matrix, b, of RHS values (assumed >=0)
%   a 1xn matrix, c, of objective fn coeffs.
%   and an initial value z (the objective value), usually zero.
%   There are three MATLAB functions to be used with these definitions
%   dict() prints the current A, b, c, z in dictionary format
%   ratios(j) determines all upper bounds for entering variable xj.
%   lppivot(i,j) modifies A, b, c, z by pivoting on eqn i, variable j
%   Define A, b, c, z in the space indicated, then run this script. The
%   three functions dict, ratios, and lppivot can then be used.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Contents of dict.m
 
function dict()
%dict is a function to print out the current A,b,c,z in dictionary format.
global A b c m n z bas nonbas myeps
 
fprintf('zeta = %8.2f',z)
sortnonbas=sort(nonbas);
for i=1:n-m
    var = sortnonbas(i);
    %pos = find(vars==var);
    if c(1,var) < 0
        fprintf('  - %6.2f x%d',-c(1,var),var)
    else    
        fprintf('  + %6.2f x%d',c(1,var),var)
    end
end
fprintf('\n')
fprintf('---------------')
for i=1:n-m
    fprintf('-------------')
end
fprintf('\n')
for i=1:m
   fprintf('x%d   = %8.2f',bas(1,i),b(i,1))
for j=1:n-m
    var = sortnonbas(j);
    if A(i,var) < -myeps
        fprintf('  + %6.2f x%d',-A(i,var),var)
    elseif A(i,var) > myeps
        fprintf('  - %6.2f x%d',A(i,var),var) 
    else
        fprintf('             ')
    end
end
fprintf('\n')
end
end
