Evaluating Polynomials

To evaluate a polynomial at an element of a Galois field, use polyval. It behaves like the ordinary MATLAB polyval function when given exactly two input arguments. The example below evaluates a polynomial at several elements in a field and checks the results using .^ and .* in the field.

m = 4;
apoly = gf([4 5 3],m); % A^2 x^2 + (A^2 + 1) x + (A + 1)
x0 = gf([0 1 2],m); % Points at which to evaluate the polynomial
y = polyval(apoly,x0)

a = gf(2,m); % Primitive element of the field, corresponding to A.
y2 = a.^2.*x0.^2 + (a.^2+1).*x0 + (a+1) % Check the result.

The output is below.

y = GF(2^4) array. Primitive polynomial = D^4+D+1 (19 decimal)
 
Array elements = 
 
     3     2    10


y2 = GF(2^4) array. Primitive polynomial = D^4+D+1 (19 decimal)
 
Array elements = 
 
     3     2    10

The first element of y evaluates the polynomial at 0 and, therefore, returns the polynomial's constant term of 3.


© 1994-2005 The MathWorks, Inc.