📄 gfrootod.m
字号:
function [rt, rt_tp, alph] = gfrootod(f, ord, p)
%GFROOTOD Finds roots for GF(p) polynomial f(X) in the field GF(p^ord)
% (This is an old version of GFROOTS.)
%
% RT = GFROOTS(F) finds all roots RT for GF(2) polynomial F(X) in the
% GF(2^ORD), where ORD is the degree of polynomial F(X). The default
% polynomial generating GF(2^ORD) is defined in GFPRIMDF.
%
% RT = GFROOTS(F, ORD) finds all roots RT for GF(2) polynomial F(X) in
% GF(2^ORD). GF(2^ORD) is a field generated by the default degree ORD
% primitive polynomial, where ORD is a positive integer. ORD should be
% larger or equals to the degree of F(X). When ORD is a vector in GF(2)
% instead of a positive number, ORD is a primitive polynomail generated
% GF(2^DEG), where DEG is the degree of ORD(X). DEG should be greater
% than the degree of F(X). The output roots RT is an column vector with
% a length equals to the degree of F(X). RT = [i, j, ..., k] means that
% the roots of F(X) are the elements alpha^i, alpha^j, ..., alpha^k
% in GF(2^ORD). The list of GF(P^ORD) can be found by using
% [tp, idx] = gftuple([-1:P^ORD], ORD, P)
% This function outputs only the distinct roots of the polynomial F(X)
% in the field.
%
% RT = GFROOTS(F, ORD) finds all roots RT for GF(P) polynomial F(X) in
% GF(P^ORD).
%
% [RT, RT_TUPLE] = GFROOTS(...) outputs the roots RT and the M-tuple of
% of RT. Each row of RT_TUPLE represents the ORD-tuple representation
% of RT.
%
% [RT, RT_TUPLE, ALPH] = GFROOTS(...) outputs the ORD-tuple of all
% powers generated by the primitive polynomial.
%
% See also: gfrepcov, hammgen, gfprimdf, gftuple.
% Wes Wang 6/27/94.
% Copyright (c) 1995-96 by The MathWorks, Inc.
% $Revision: 1.1 $ $Date: 1996/04/01 17:59:51 $
% routine check
if nargin < 1
error('Not enough input variable in calling GFROOTS.')
elseif nargin < 2
ord = length(f) - 1;
end;
if nargin < 3
p = 2;
end;
if length(ord) > 1
dim = length(ord) - 1;
else
dim = ord;
ord = gfprimdf(dim, p);
end;
length_alph = p^dim;
% a list of all elements in GF(P^DIM)
alph = gftuple([-1 : length_alph - 2]', ord, p);
length_f = length(f);
rt = [];
rt_tp = [];
i = 1;
while((i <= length_alph) & (length(rt) < length_f))
if i==1
tmp = f(1);
elseif i==2
tmp = rem(sum(f), p);
else
tmp = [f(1) zeros(1,dim-1)];
for j = 2 : length_f
if f(j) ~= 0
k = (i - 2) * (j - 1) + 2;
if k > length_alph
k = rem(k - 2, length_alph - 1) + 2;
end
tmp = gfadd(tmp, alph(k,:) * f(j), p);
end;
end;
end;
if max(tmp) == 0
rt = [rt i];
rt_tp = [rt_tp; alph(i,:)];
end;
i = i + 1;
end;
rt = rt(:) - 2;
ind = find(rt < 0);
if ~isempty(ind)
rt(ind) = Inf * rt(ind);
end
%--end of GFROOTod.m--
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -