eulerPhi
Syntax
Description
evaluates
the Euler phi function
or (also known as the totient function) for a positive integer
p
= eulerPhi(n
)n
.
Examples
Multiplicative Property of Euler Phi Function
Compute the Euler phi function for the integer .
p = eulerPhi(35)
p = 24
The Euler phi function satisfies the multiplicative property if the two integers and are relatively prime (also known as coprime). The integer factorization of 35 is 7 and 5, which are relatively prime. Show that satisfies the multiplicative property.
Calculate and for the two factors.
px = eulerPhi(7)
px = 6
py = eulerPhi(5)
py = 4
Verify that px
and py
satisfy the multiplicative property.
p = px*py
p = 24
Euler's Product Formula
If a positive integer has prime factorization with distinct prime factors , then the Euler phi function satisfies the product formula
.
The integer has distinct prime factors and . Show that satisfies the Euler's product formula.
Declare as a symbolic number and evaluate .
n = sym(36)
n =
p = eulerPhi(n)
p =
List the prime factors of .
f_n = factor(n)
f_n =
Substitute the prime factors and into the product formula.
p_product = n*(1-1/2)*(1-1/3)
p_product =
Euler's Theorem
Euler's theorem states that if and only if the two positive integers and are relatively prime. Show that the Euler phi function satisfies Euler's theorem for the integers and .
a = 15; n = 4; isCongruent = powermod(a,eulerPhi(n),n) == mod(1,n)
isCongruent = logical
1
Confirm that a
and n are relatively prime.
g = gcd(a,n)
g = 1
Mean Value of Euler Phi Function Results
Calculate the Euler phi function for the integers from 1 to 1000.
P = eulerPhi(1:1000);
Find the mean value of .
Pave = mean(P./(1:1000))
Pave = 0.6082
Input Arguments
n
— Input
number | vector | matrix | array | symbolic number | symbolic array
Input, specified as a number, vector, matrix, array, symbolic number, or symbolic
array. The elements of n
must be positive integers.
Data Types: single
| double
| sym
More About
Euler Phi Function
The Euler phi function computes the number of integers between 1 and n that are relatively prime (also known as coprime) to n. Two integers are relatively prime if there is no integer greater than one that divides them both. In other words, their greatest common divisor is one.
References
[1] Redmond, D. Number Theory: An Introduction to Pure and Applied Mathematics. New York: Marcel Dekker, 1996.
Version History
Introduced in R2020a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)