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
| function [output] = danchun(a)
format rat
raw=a;
while 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,2)
if a(1,i)<0
positive = 0;
for j=2:size(a,1)
if a(j,i)>0
positive =1;
end
end
if positive ==0
break
end
end
end
if positive ==0
output="无解1";
break
end
for i=2:size(a,2)
if x_min==0 && a(1,i)<0
x_min=i;
elseif a(1,i)>0 && x_min~=0
break
end
end
if x_min == 0
output=raw(1,:)*tag2;
break
end
tmp=9999;
y_min=0;
for i=2:size(a,1)
if a(i,x_min)>0 && a(i,1)/a(i,x_min)<tmp
y_min = i;
tmp = a(i,1)/a(i,x_min);
end
end
if y_min==0
output="无解2";
break
end
a(y_min,:)=a(y_min,:)/a(y_min,x_min);
for i=1:size(a,1)
if i==y_min
continue
end
a(i,:)=a(i,:) - a(y_min,:) * a(i,x_min);
end
disp("----------------------------------------------------------------------------------------------------");
end
end
|