Method on @sym: mod (x, n)
Method on @sym: mod (x, n, false)

Element-wise modular arithmetic on symbolic arrays and polynomials.

Example:

mod([10 3 1], sym(3))
  ⇒ ans = (sym) [1  0  1]  (1×3 matrix)

If any of the entries contain variables, we assume they are univariate polynomials and convert their coefficients to mod n:

syms x
mod(5*x + 7, 3)
  ⇒ (sym) 2⋅x + 1
mod(x, 3)   % (coefficient is 1 mod 3)
  ⇒ (sym) x

You can disable this behaviour by passing false as the third argument:

q = mod(x, 3, false)
  ⇒ q = (sym) x mod 3
subs(q, x, 10)
  ⇒ ans = (sym) 1

syms n integer
mod(3*n + 2, 3, false)
  ⇒ (sym) 2

See also: @sym/coeffs.

Package: symbolic