换为基变量decide=find(g1(1,[1:m+n])>0);%再进行查找endifg1(1,s1)>0%无解情况flag=-1;endifg1(1,s1)==0%置空矩阵8g1(1,:)=[];fori6=1:mA(:,n+1)=[];endfori6=1:mc(n+1)=[];enddecide=find(A1(1:m,1)>n);%查找是否有人工变量if~isempty(decide)while~isempty(decide)x1=decide(1);%存放的是人工变量的行数text=find(A(x1,1:n)~=0);%该行的所有元素都不为零的列坐标ifisempty(text)%如果text为空decide(1)=[];A1(x1,:)=[];A(x1,:)=[];m=m-1;elsei=text(1);%i保存列数A(x1,:)=A(x1,:)/A(x1,i);%进行单位化A1(x1,1)=i;c(1,:)=c(1,:)+(-1*c(1,i)*A(x1,:));fori1=1:mifi1~=x1A(i1,:)=A(i1,:)+(-1*A(i1,i)*A(x1,:));%进行换基迭代endenddecide(1)=[];%赋值为空text(1)=[];endendend9decide=find(c(1,1:n)>0);%decide存放c中该行中所有数值大于零的列数while~isempty(decide)i=decide(1);%将列数赋给itext=find(A(:,i)>0);%保存大于零的项的行数ifisempty(text)%为空的时候,则无解flag=0;%有可行解但无最优值,flag记为0c=[c;A];%将c添加到A矩阵上方的到对应解的单纯形表cpt=c;x=zeros(n,1);foro=1:nforo1=1:mifo==A1(o1,1)