func
tion [x,z]=fun5(A,B,C,N)
[m,n]=size(A);
flag=1;
z=0;
while flag
if C(:)>=0
flag=0;
x=zeros(1,n);
for i=1:m
x(N(i))=B(i);
end
z=z;
else
for i=1:n
if C(i)<0&A(1:m,i)<=0
disp('问题不可解');
flag=0;
break;
end
end
if flag
temp=0;
for i=1:n
if C(i)<temp
temp=C(i);
inb=i;
end
end
s=zeros(1,m);
for i=1:m
if A(i,inb)>0
s(i)=B(i)/A(i,inb);
end
end
M=1000;
for i=1:m
if s(i)>0&s(i)<M
M=s(i);
outb=i+1;
end
end
A(outb,:)=A(outb,:)/A(outb,inb);
for i=1:m
if i~=outb
A(i,:)=A(i,:)-A(outb,:)*A(i,inb);
B(i)=B(i)-B(outb)*A(i,inb);
end
end
for i=1:n
C(i)=C(i)-A(outb,:)*C(inb); %老提示这里维数不匹配,但这里C矩阵是1行n列,A矩阵这里是下标outb对应的行,也是一行n列
end
z=z-B(outb)*C(inb);
for i=1:m
if i==outb
N(i)=inb;
end
end
end
end
end
一周热门 更多>