在网上下载了用对matlab实现对偶单纯性的程序,但程序运算结果与我使用lingo计算的结果不一致,求大神解决,原程序如下:
function x=lindual(c,A,b)
[n1,n2]=size(A);
A=[-A,eye(n1)];c=[-c,zeros(1,n1)];
x1=[zeros(1,n2),b'];lk=[n2+1:n1+n2];
b=-b;
while(1)
x=x1(1:n2);
s1=[lk',b,A];
c;
x1;
cc=[];ci=[];
for i=1:n1
if b(i)<0
cc=[cc,b(i)];
ci=[ci,i];
end
end
nc=length(cc);
if nc==0
fprintf('达到最优解');
break
end
cliu=cc(1);
cl=ci(1);
for j=1:nc
if abs(cc(j))>abs(cliu)
cliu=cc(j);
cl=j;
end
end
cc1=[];ci1=[];
for i=1:n1+n2
if A(cl,i)<0
cc1=[cc1,A(cl,i)];
ci1=[ci1,i];
end
end
nc1=length(cc1);
if nc1==0
fprintf('无可行解');
break
end
cliu=c(ci1(1))/cc1(1);
cl1=ci1(1);
for j=1:nc1
if c(ci1(j))/cc1(j)<cliu
cliu=c(ci1(j))/cc1(j);
cl1=ci1(j);
end
end
b(cl)=b(cl)/A(cl,cl1);
A(cl,:)=A(cl,:)/A(cl,cl1);
for k=1:n1
if k~=cl
b(k)=b(k)-b(cl)*A(k,cl1);
A(k,:)=A(k,:)-A(cl,:).*A(k,cl1);
end
end
c=c-c(cl1).*A(cl,:);
x1(lk(cl))=0;
lk(cl)=cl1;
for kk=1:n1
x1(lk(kk))=b(kk);
end
x=x1(1:n2);
end
我的线性规划问题是
Max=x1+x2+x3+x4;
x2+x3+x4<=11.2;
x1+x2-x3-x4>=0;
x2-0.8*x1<0;
x1+x4<=9.5;
x1<=10;
x2<=10;
x3<=10;
x4<=10;
我应该怎么调用函数
function x=lindual(c,A,b)
[n1,n2]=size(A);
A=[-A,eye(n1)];c=[-c,zeros(1,n1)];
x1=[zeros(1,n2),b'];lk=[n2+1:n1+n2];
b=-b;
while(1)
x=x1(1:n2);
s1=[lk',b,A];
c;
x1;
cc=[];ci=[];
for i=1:n1
if b(i)<0
cc=[cc,b(i)];
ci=[ci,i];
end
end
nc=length(cc);
if nc==0
fprintf('达到最优解');
break
end
cliu=cc(1);
cl=ci(1);
for j=1:nc
if abs(cc(j))>abs(cliu)
cliu=cc(j);
cl=j;
end
end
cc1=[];ci1=[];
for i=1:n1+n2
if A(cl,i)<0
cc1=[cc1,A(cl,i)];
ci1=[ci1,i];
end
end
nc1=length(cc1);
if nc1==0
fprintf('无可行解');
break
end
cliu=c(ci1(1))/cc1(1);
cl1=ci1(1);
for j=1:nc1
if c(ci1(j))/cc1(j)<cliu
cliu=c(ci1(j))/cc1(j);
cl1=ci1(j);
end
end
b(cl)=b(cl)/A(cl,cl1);
A(cl,:)=A(cl,:)/A(cl,cl1);
for k=1:n1
if k~=cl
b(k)=b(k)-b(cl)*A(k,cl1);
A(k,:)=A(k,:)-A(cl,:).*A(k,cl1);
end
end
c=c-c(cl1).*A(cl,:);
x1(lk(cl))=0;
lk(cl)=cl1;
for kk=1:n1
x1(lk(kk))=b(kk);
end
x=x1(1:n2);
end
我的线性规划问题是
Max=x1+x2+x3+x4;
x2+x3+x4<=11.2;
x1+x2-x3-x4>=0;
x2-0.8*x1<0;
x1+x4<=9.5;
x1<=10;
x2<=10;
x3<=10;
x4<=10;
我应该怎么调用函数