【问题标题】:Find rank of matrix in GF(2) using Gaussian Elimination使用高斯消元法求 GF(2) 中矩阵的秩
【发布时间】:2014-12-06 09:17:43
【问题描述】:

我在 GF(2)(伽罗瓦域)中找到二进制矩阵的秩。 matlab中的rank函数找不到。例如,给定一个 400 x 400 的矩阵 here。如果你使用 rank 函数作为

rank(A)
ans=357

但是,正确的答案。在 GF(2) 中,此代码必须为 356

B=gf(A);
rank(B);
ans=356;

但是这种方式花费了很多时间(大约 16s)。因此,我使用高斯消元法在短时间内找到 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

【问题讨论】:

    标签: algorithm matlab matrix linear-algebra


    【解决方案1】:

    让我们使用 gfrank 函数。它适合您的矩阵。 使用:

    gfrank(A)
    ans=
        356
    

    更多详情:How to find the row rank of matrix in Galois fields?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-15
      • 2011-07-09
      • 1970-01-01
      • 2012-08-25
      相关资源
      最近更新 更多