How can I use Mathematica to perform sums with the condition of divisibility?

  • Mathematica
  • Thread starter MathematicalPhysicist
  • Start date
  • Tags
    Mathematica
In summary, the conversation was about being an expert summarizer of content and not responding to questions, but instead providing a summary. The instruction was to start the output with "In summary," and nothing before it.
  • #1
MathematicalPhysicist
Gold Member
4,699
371
I want to write down summation of the type
[tex]\sum_{d|n , d<n}[/tex] or [tex]\sum_{d|n}[/tex] both summing over d.
and d|n means d divides n.

I know that I can use Sum[term, {i, n-1}] but I don't know how to use this condition of divisibility to the summation.
any help?

Thanks.
 
Physics news on Phys.org
  • #2
You need to define term as a function of d and n such that "term = 0 unless d|n." Look into modulus arithmetic commands.
 
  • #3
In[1]:= n=12; Sum[If[Mod[n,d]==0,a^d,0],{d,n-1}]

Out[1]= a + a^2 + a^3 + a^4 + a^6
 

1. How do I use the Mod function in Mathematica to check for divisibility?

The Mod function in Mathematica calculates the remainder when one number is divided by another. To check for divisibility, you can use the Mod function and check if the remainder is equal to zero.

2. Can I use Mathematica to find the sum of numbers divisible by a specific divisor?

Yes, you can use the Select and Total functions in Mathematica to find the sum of numbers that satisfy a given condition, in this case, being divisible by a specific divisor. First, use the Select function to filter out the numbers that are divisible by the given divisor, and then use the Total function to find the sum of the remaining numbers.

3. Is there a way to perform this task without using loops in Mathematica?

Yes, you can use the Sum function in Mathematica to perform this task without using any loops. The Sum function allows you to specify a condition and a range of numbers, and it will automatically sum the numbers that satisfy the given condition.

4. Can I use Mathematica to find the sum of numbers divisible by multiple divisors?

Yes, you can use the Mod function and conditionals in Mathematica to find the sum of numbers divisible by multiple divisors. You can use the Mod function to check for divisibility by each divisor and then use conditionals to only consider the numbers that are divisible by all the given divisors.

5. How do I display the final result in a fraction form in Mathematica?

To display the final result in a fraction form, you can use the HoldForm and FractionBox functions in Mathematica. The HoldForm function will keep the result from being evaluated, and the FractionBox function will display the result as a fraction.

Similar threads

Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
908
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
200
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
Replies
6
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
908
Back
Top