Algorithm 用高斯消去法求GF(2)中矩阵的秩
在GF(2)(伽罗瓦域)中求二元矩阵的秩。matlab中的秩函数无法找到它。例如,给定一个矩阵400 x 400作为。如果将秩函数用作Algorithm 用高斯消去法求GF(2)中矩阵的秩,algorithm,matlab,matrix,linear-algebra,Algorithm,Matlab,Matrix,Linear Algebra,在GF(2)(伽罗瓦域)中求二元矩阵的秩。matlab中的秩函数无法找到它。例如,给定一个矩阵400 x 400作为。如果将秩函数用作 rank(A) ans=357 但是,GF(2)中的正确答案必须为356(按此代码) B=gf(A); rank(B); ans=356; 但是这种方法花费了很多时间(大约16秒)。因此,我使用高斯消去法在很短的时间内找到GF(2)中的秩。但是,它的效果并不好。有时,它返回真实值,但有时返回错误值。请查看我的代码并让我知道代码中的问题。注意,与上面的代码相比
rank(A)
ans=357
但是,GF(2)中的正确答案必须为356(按此代码)
B=gf(A);
rank(B);
ans=356;
但是这种方法花费了很多时间(大约16秒)。因此,我使用高斯消去法在很短的时间内找到GF(2)中的秩。但是,它的效果并不好。有时,它返回真实值,但有时返回错误值。请查看我的代码并让我知道代码中的问题。注意,与上面的代码相比,它花费的时间非常少
function rankA =GaussEliRank(A)
tic
mat = A;
[m n] = size(A); % read the size of the original matrix A
for i = 1 : n
j = find(mat(i:m, i), 1); % finds the FIRST 1 in i-th column starting at i
if isempty(j)
mat = mat( sum(mat,2)>0 ,:);
rankA=rank(mat);
return;
else
j = j + i - 1; % we need to add i-1 since j starts at i
temp = mat(j, :); % swap rows
mat(j, :) = mat(i, :);
mat(i, :) = temp;
% add i-th row to all rows that contain 1 in i-th column
% starting at j+1 - remember up to j are zeros
for k = find(mat( (j+1):m, i ))'
mat(j + k, :) = bitxor(mat(j + k, :), mat(i, :));
end
end
end
%remove all-zero rows if there are some
mat = mat( sum(mat,2)>0 ,:);
if any(sum( mat(:,1:n) ,2)==0) % no solution because matrix A contains
error('No solution.'); % all-zero row, but with nonzero RHS
end
rankA=sum(sum(mat,2)>0);
end
让我们使用gfrank函数。它适合您的矩阵。 使用: 更多详情:
gfrank(A)
ans=
356