Professional Documents
Culture Documents
Simplex
Simplex
%SIMPLEX
%Simplex method.
%Option of rational number format.
%Option of all steps.
%Calling format: simplex(A),
%where A is the initial simplex tableau.
tol=1e-20;
[n,m]=size(P);
format compact
disp(' ')
h=input('Rational numbers? y/n: ','s');
g=input('All steps? y/n: ','s');
disp(' ')
disp('initial simplex tableau')
if h=='y'
disp(rats(P))
else
disp(P)
end
disp(' ')
if g=='y';
disp('[press Enter at each step to continue]')
disp(' ')
pause
end
flag='T';
while flag=='T'
%find pivot column
t=0;
for pc=1:m-1,
if P(n,pc)-t<0
t=P(n,pc);
pivotcol=pc;
end
end
if t==0;
flag='F';
end
%find pivot
if flag == 'T'
tt=1E+100; %suitable large number
for pr=1:n-1,
if P(pr,pivotcol)>0
if P(pr,m)/P(pr,pivotcol)<tt
tt=P(pr,m)/P(pr,pivotcol);
pivotrow=pr;
end
end
end
end