How Can Mathematica Calculate the Digital Sum of a Number in Base 10?

Click For Summary

Discussion Overview

The discussion revolves around how to calculate the digital sum of a number in base 10 using Mathematica. Participants are exploring commands and functions within the software to achieve this task.

Discussion Character

  • Technical explanation

Main Points Raised

  • One participant asks for the command in Mathematica to sum the digits of a number in base 10.
  • Another participant provides examples of input and expected output for clarity.
  • A third participant confirms the request and seeks further clarification on how to implement it.
  • One participant references an external link that may provide relevant information on digit sums.
  • A participant shares their attempt to define a function in Mathematica but reports that it did not yield results.
  • Another participant suggests that the issue arises from not executing the function correctly and offers a simpler method to evaluate the expression directly.

Areas of Agreement / Disagreement

Participants generally agree on the goal of calculating the digital sum, but there is no consensus on the correct implementation method within Mathematica, as evidenced by differing approaches and outcomes.

Contextual Notes

Some limitations include potential misunderstandings of function definitions in Mathematica and the need for correct evaluation methods. There may also be dependencies on specific syntax or commands that are not fully explored in the discussion.

Who May Find This Useful

This discussion may be useful for Mathematica users looking to perform digit sum calculations, particularly those who are new to the software or programming in general.

amcavoy
Messages
663
Reaction score
0
Which command in Mathematica will give me the sum of the digits of a number in base 10? Thanks.
 
Physics news on Phys.org
So you want it to give you something like this:

Input: 380234
Output: 20
Input: 32138
Output: 17

?
 
Yes, exactly. Do you know how that is done?
 
I had already found that; nothing happens when I plug that into Mathematica. I entered:

Code:
s[3^14, 10] := Plus @@ IntegerDigits[3^14, 10]
and then nothing came out. Is this the correct way to enter it? For this example I was trying to compute the sum of the digits of 314 in base 10. Thanks.
 
That's because you're attempting to define a "function" and haven't asked Mathematica to do anything with it.

For a quick answer, just copy and paste the right side into an input line and evaluate it.
 

Similar threads

  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 20 ·
Replies
20
Views
7K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 10 ·
Replies
10
Views
2K