No BSD License
-
bern(n)
Bern Bernoulli number
-
betad(z)
BETAD Dirichlet Beta function
-
binomial(n,d)
BINOMIAL calculate the binomial coefficient
-
deta(z,k)
DETA Calculates Dirichlet functions of the form
-
erfz(zz)
ERFZ Error function for complex inputs
-
eta(z)
ETA Dirichlet Eta function
-
euler(n)
Euler Euler number
-
eulergamma
Euler-Mascheroni constant = -Psi(1) = 0.5772156649015328606...
-
fact(n)
FACT Vectorized Factorial function
-
factd(n)
FACTD Double Factorial function = n!!
-
gamma(z)
GAMMA Gamma function valid in the entire complex plane.
-
gammaln(z)
GAMMALOG Natural Log of the Gamma function valid in the entire complex plane.
-
genocchi(z)
Genocchi number
-
harm(z)
Harm Harmonic sum function valid in the entire (complex) plane.
-
lambda(z)
LAMBDA Dirichlet Lambda function
-
poch(z,n)
-
psi(z)
Psi Psi (or Digamma) function valid in the entire complex plane.
-
psin(n,z)
Psin Arbitrary order Polygamma function valid in the entire complex plane.
-
totient(n)
TOTIENT calculates the totient function (also
-
zeta(z)
ZETA Riemann Zeta function
-
View all files
from
Special Functions math library
by Paul Godfrey
Collection of Special Functions programs.
|
| totient(n) |
function [t] = totient(n)
%TOTIENT calculates the totient function (also
% called the Euler Phi function) of any
% positive integer n.
%
%Usage: f = totient(n)
%
% The totient function computes the number of
% integers from the set (1...n-1) that are
% relatively prime to n. It can be used to
% describe the multiplicative structure of
% all Galois fields GF(q).
%
% n can be any size
%
% Tested under version 5.2.0
%
%Ref: "Error Control Systems" by S.B Wicker
%
%see also Primes, Factor
% Paul Godfrey
% pgodfrey@conexant.com
% 10-23-2001
[r c]=size(n);
n=reshape(n,1,r*c);
t=zeros(1,r*c);
f=zeros(1,10);
for k=1:r*c;
nk=n(k);
f=unique(factor(nk));
t(k)=nk*prod(1-1./f);
end
t=reshape(t,r,c);
p=find(n==1);
t(p)=1;
t=round(t);
return
%a demo of this program is
n=(1:50).';
t=totient(n);
[n t]
|
|
Contact us at files@mathworks.com