How to use if-function for arithmetic properties properly?
Show older comments
Hello everyone,
Im working on a project about the Ramanujans qth summation containing elements of signal processing. I try to simulate the entire formula via matlab yet Im not capable of finishing the if function with all the 3 properties (see picture) of the arithmetic theorem. This is my best attempt....
q = 12
primesfactorization = factor((q))
numbers=hist(primesfactorization, unique(primesfactorization));
m1 = numbers(1,1);
m2 = numbers(1,2);
p1=(primesfactorization(1,1)^m)
p2=primesfactorization(1,3)
XX Something is missing here, asking if p1 is a prime number then
if (q1)== mrdivide(q1,k)
q1 = q1-1
else(q1)~= mrdivide(q1,k)
q1 = -1
end
or p1= p^m for p is a prime and m<1 then
.....
Answers (1)
David Hill
on 3 Jun 2020
If you are trying to comute the ramanujan sum it should be something like this:
function s = ramanujanSum(a,n)
f=factor(a);
s=1;
for k=unique(f)
b=nnz(f==k);
if b==1
if mod(n,k)==0
s=s*(k-1);
else
s=-s;
end
elseif gcd(k^(b-1),n)==1
s=0;
return;
elseif gcd(k^b,n)==1
s=s*(-k^(b-1));
else
s=s*k^(b-1)*(k-1);
end
end
1 Comment
David Hill
on 3 Jun 2020
My code is generating the qth sum at n.
function c = ramanujanSum(q,n)
f=factor(q);
c=1;
for k=unique(f)
b=nnz(f==k);%exponent of prime factor
if b==1
if mod(n,k)==0
c=c*(k-1);
else
c=-c;
end
elseif gcd(k^(b-1),n)==1
c=0;
return;
elseif gcd(k^b,n)==1
c=c*(-k^(b-1));
else
c=c*k^(b-1)*(k-1);
end
end
Categories
Find more on Audio and Video Data in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!