function [Tnew, Bnew,flg] = SimplexTableau(B,r,s,T) % % This function updates a SimplexTableau % % Written by Ming Gu for Math 170 % March 2007 % % On input: % B: current basis index % T: current Tableau % r: B(r)-th column is to LEAVE the index. % s: s-th column is to JOIN the index. % % On output: % % flg: flg == 0 indicates SUCCESS in updating, % flg == 1 indicates FAILURE in updating, % Bnew: New basis index % Tnew: New Tableau % % % initialize flg. % flg = 0; % % find dimensions of T. % [mt,nt] = size(T); % % Set up Bnew % B = B(:); Bnew = [B(1:r-1);s;B(r+1:mt)]; % % Setup Tnew % Tnew = zeros(mt,nt); if (T(r,s) == 0) % % This is indication of degeneracy. Quit. % flg = 1; return; end % % This is the normal case. Proceed. % Tnew(:,Bnew) = eye(length(Bnew)); Tnew(:,B(r)) =-T(:,s)/T(r,s); Tnew(r,B(r)) = 1/T(r,s); Bbar = setdiff((1:nt)',[B;s]); Temp = T(r,Bbar)/T(r,s); Tnew(:,Bbar) = T(:,Bbar) - T(:,s)*Temp; Tnew(r,Bbar) = Temp;