## Syntax

```c = gfadd(a,b) c = gfadd(a,b,p) c = gfadd(a,b,p,len) c = gfadd(a,b,field) ```

## Description

Note

This function performs computations in GF(pm) where p is prime. To work in GF(2m), apply the + operator to Galois arrays of equal size. For details, see Example: Addition and Subtraction.

`c = gfadd(a,b) ` adds two GF(2) polynomials, `a` and `b`, which can be either polynomial character vectors or numeric vectors. If `a` and `b` are vectors of the same orientation but different lengths, then the shorter vector is zero-padded. If `a` and `b` are matrices they must be of the same size.

`c = gfadd(a,b,p) ` adds two GF(`p`) polynomials, where `p` is a prime number. `a`, `b`, and `c` are row vectors that give the coefficients of the corresponding polynomials in order of ascending powers. Each coefficient is between 0 and `p`-1. If `a` and `b` are matrices of the same size, the function treats each row independently.

`c = gfadd(a,b,p,len) ` adds row vectors `a` and `b` as in the previous syntax, except that it returns a row vector of length `len`. The output `c` is a truncated or extended representation of the sum. If the row vector corresponding to the sum has fewer than `len` entries (including zeros), extra zeros are added at the end; if it has more than `len` entries, entries from the end are removed.

`c = gfadd(a,b,field) ` adds two GF(pm) elements, where m is a positive integer. `a` and `b` are the exponential format of the two elements, relative to some primitive element of GF(pm). `field` is the matrix listing all elements of GF(pm), arranged relative to the same primitive element. `c` is the exponential format of the sum, relative to the same primitive element. See Representing Elements of Galois Fields for an explanation of these formats. If `a` and `b` are matrices of the same size, the function treats each element independently.

## Examples

collapse all

Sum $2+3x+{x}^{2}$ and $4+2x+3{x}^{2}$ over GF(5).

`x = gfadd([2 3 1],[4 2 3],5)`
```x = 1×3 1 0 4 ```

Add the two polynomials and display the first two elements.

`y = gfadd([2 3 1],[4 2 3],5,2)`
```y = 1×2 1 0 ```

For prime number `p` and exponent `m`, create a matrix listing all elements of GF(p^m) given primitive polynomial $2+2x+{x}^{2}$.

```p = 3; m = 2; primpoly = [2 2 1]; field = gftuple((-1:p^m-2)',primpoly,p);```

Sum ${A}^{2}$ and ${A}^{4}$. The result is $A$.

`g = gfadd(2,4,field)`
```g = 1 ```

## Version History

Introduced before R2006a