单纯形法MATLAB程序.doc
Four short words sum up what has lifted most successful individuals above the crowd: a little bit more.-author-date单纯形法MATLAB程序单纯形法(Matlab程序)单纯形法(Matlab程序)% 单纯形法(Matlab程序) a=input('input the major matrix A ');b=input('input the matrix b ');n=input('input the judgement ');%g为计数器(确定循环次数)g=0;while g<40 %确定非负 alength=max(size(n); blength=max(size(b); m=0; for i=1:alength if n(i)>=0 m=m+1; end end; if m=alength x=b; break end; %找K s=min(n); for i=1:alength if n(i)=s k=i; break end; end; %ai,k的非负性 m=0; for i=1:blength if a(i,k)<0 m=m+1; end; end; if m=blength disp('x does not exit'); judge=1; break end; %找L 确定主元 cc=100000; for i=1:blength if a(i,k)>0 if (b(i)/a(i,k)<cc cc=b(i)/a(i,k); end end end; for i=1:blength if a(i,k)=0 if (b(i)/a(i,k)=cc l=i; break end end end; %计算,a标准化 zu=a(l,k); aa=a; for i=1:l-1 for j=1:alength aa(i,j)=a(i,j)-a(l,j)*a(i,k)/a(l,k); end end; for i=l+1:blength for j=1:alength aa(i,j)=a(i,j)-a(l,j)*a(i,k)/a(l,k); end end; for j=1:alength aa(l,j)=a(l,j)/zu; end; %b的判别 bb=b; bb(l)=b(l)/zu; for i=1:l-1 bb(i)=b(i)-b(l)*a(i,k)/a(l,k); end; for i=l+1:blength bb(i)=b(i)-b(l)*a(i,k)/a(l,k); end; b=bb; %确定判别数 tt=n; for j=1:alength tt(j)=n(j)-a(l,j)*n(k)/a(l,k); end; n=tt; a=aa; %显示单纯形表sa sa=b' aa; 0 n; disp('单纯表示例'); disp(g+1); disp(sa); g=g+1; judge=2; end;if judge=2 q=0; result=zeros(alength,2); for j=1+q:alength if n(j)=0 t=a(:,j); zu=find(t); result(j,1)=j; result(j,2)=x(zu); q=q+1; end if n(j)>0 result(j,1)=q+1; q=q+1; end end; disp('最优解'); disp(result); disp('循环次数'); g end-