⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gfrank.m

📁 数字通信第四版原书的例程
💻 M
字号:
function rk = gfrank(a, p)
%GFRANK Calculates the rank of a matrix in GF(P).
%       RK = GFRANK(A) calculates the rank of matrix A in GF(2).
%
%       RK = GFRANK(A, P) calculates the rank of matrix in GF(P).
%
%       See also GFLINEQ.

% The method use here is similar to the Gaussian elimination.
% The algorithm has taken the advantage of the binary computation
% double sided elimination has been used.

%       Wes Wang 10/7/95
%       Copyright (c) 1995-96 by The MathWorks, Inc.
%       $Revision: 1.1 $  $Date: 1996/04/01 17:59:39 $

if nargin < 1
    error('Not enough input variables')
elseif nargin < 2
    p = 2;
end;
vld = 0;

% make matrix a to be a long matrix.
[n, m] = size(a);
if n < m
    a = a';
end;

x = a(:);
if ((max(x) >=p) | (min(x) < 0) | ~isempty(find(floor(x) ~= x)))
    error('Element in A or B exceeded the defined field')
end;
[n, m] = size(a);
k = 1;
i = 1;
ii = [];
kk = [];

% forward major element selection
while (i <= n) & (k <= m)
    % make the diagonal element be one or jump one line.
    while (a(i,k) == 0) & (k < m)
        ind = find(a(i:n, k) ~= 0);
        if isempty(ind)
            k = k + 1;
        else
            indx = find(a(i:n, k) == 1);
            if isempty(indx)
               ind_major = ind(1);
            else
               ind_major = indx(1);
            end;
            j = i + ind_major - 1;
            tmp = a(i, :);
            a(i,:) = a(j, :);
            a(j, :) = tmp;
        end;
    end;

    % clear all non-zero elements in the collumn except the major element.
    if (a(i,k) ~= 0)
     % to make major element to be one.
        if (a(i,k) ~= 1)
           a(i,:) = rem(a(i,k)^(p-2) * a(i,:), p);
        end;
        ind = find(a(:,k) ~= 0)';
        ii = [ii i];
        kk = [kk k];
        vec = [k:m];
        for j = ind
            if j > i
                % to make sure the colum will be zero except the major element.
                a(j, vec) = rem(a(j, vec) + a(i, vec) * (p - a(j, k)), p);
            end;
        end;
        k = k + 1;
    end;
    i = i + 1;
end;

rk = max( find( sum( a') > 0));

% --- end of GFRANK.M--

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -