function [JJ,KK,bb,id]= simplexII(n,m,A,b,F,bi0)
% Simplexova metoda II-faza ,b>=0, v matici posledny riadok je ucelova
% funkcia s (-1) koeficientami c ; ide o maximalizaciu c.x; posledny stlpec AS
% patri ucelovej premennej; card(J+K)=n, predpokladame m<n; A=(m+1)x n;
%if F=0 phase II parameter bio only formal. 
%If F=1 : phase I prepares
%matrix A and bi0 and this prepares only feasible basis via simplex_k m-file
 p=n;
for i=1:m+1
J(i)=p+i;
end
for i=1:p
K(i)=i;
end
E=eye(m+1,m+1);
AS=[A E];
np=p+m+1;
if F==0
bs=[b;0];
else 
bs=[b;bi0];
end
di=0;
while di==0
    [JJ,KK,bb,id]=simplex_k(np,m,J,K,AS,bs);
    J=JJ,K=KK,di=id
end
 'otimal basis'
JJ , KK
    'optimal solution is'
    bb
    'last component is cost function value' 
    
   
