1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
| function [outputArg1] = duiou(a,n)
format rat
raw=a;
times=0;
while 1
if nargin==2 && times>=n
break
end
times=times+1;
tag="";
tag2=zeros(size(a,2),1);
tag2(1)=-1;
for i=2:size(a,1)
for j=2:size(a,2)
if a(i,j)==1 && ~any([a(2:i-1,j);a(i+1:size(a,1),j)])
tag(i,1)="x"+(j-1);
tag2(j,1)=a(i,1);
end
end
end
disp([tag rats(a)])
x_min=0;
positive = 1;
for i=2:size(a,1)
if a(1,i)<0
positive = 0;
for j=2:size(a,2)
if a(i,j)>0
positive =1;
end
end
if positive ==0
break
end
end
end
if positive ==0
outputArg1="无解1";
break
end
for i=2:size(a,1)
if x_min==0 && a(i,1)<0
x_min=i;
elseif a(i,1)>0 && x_min~=0
break
end
end
if x_min == 0
outputArg1=raw(1,:)*tag2;
break
end
tmp=9999;
y_min=0;
for i=2:size(a,2)
if a(x_min,i)<0 && -1*a(1,i)/a(x_min,i)<tmp
y_min = i;
tmp = -1*a(1,i)/a(x_min,i);
end
end
if y_min==0
outputArg1="无解2";
break
end
a(x_min,:)=a(x_min,:)/a(x_min,y_min);
for i=1:size(a,1)
if i==x_min
continue
end
a(i,:)=a(i,:) - a(x_min,:) * a(i,y_min);
end
disp("----------------------------------------------------------------------------------------------------");
end
end
|