주요 콘텐츠

isPrimitiveRoot

Determine which array elements are primitive roots

Description

TF = isPrimitiveRoot(G,N) returns a logical array containing 1 (true) for the corresponding elements of G that are primitive roots modulo N, and 0 (false) for the corresponding elements that are not primitive roots. The elements of G must be integers, and the elements of N must be positive integers.

example

Examples

collapse all

Create a row vector containing positive integers from 1 to 11. Determine if they are primitive roots modulo 11.

G = 1:11;
TF = isPrimitiveRoot(G,11)
TF = 1×11 logical array

   0   1   0   0   0   1   1   1   0   0   0

Find the smallest positive integer that is a primitive root modulo 11.

Z1 = find(TF,1)
Z1 = 
2

Show all positive integers (less than or equal to 11) that are primitive roots modulo 11.

Z = G(TF)
Z = 1×4

     2     6     7     8

Create a row vector containing integers from –15 to 15. Find the integers that are primitive roots modulo 15.

G = -15:15;
Z = G(isPrimitiveRoot(G,15))
Z =

  1×0 empty double row vector

The integer 15 has no primitive roots.

Input Arguments

collapse all

Base, specified as a number, vector, matrix, array, symbolic number, or symbolic array. The elements of G must be integers. G and N must be the same size, or else one of them must be a scalar.

Data Types: single | double | sym

Divisor, specified as a number, vector, matrix, array, symbolic number, or symbolic array. The elements of N must be positive integers. G and N must be the same size, or else one of them must be a scalar.

Data Types: single | double | sym

More About

collapse all

Version History

Introduced in R2020a