Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Digital Sums in Mathematica

  1. Apr 21, 2006 #1
    Which command in Mathematica will give me the sum of the digits of a number in base 10? Thanks.
     
  2. jcsd
  3. Apr 21, 2006 #2

    Pengwuino

    User Avatar
    Gold Member

    So you want it to give you something like this:

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

    ?
     
  4. Apr 21, 2006 #3
    Yes, exactly. Do you know how that is done?
     
  5. Apr 21, 2006 #4

    dav2008

    User Avatar
    Gold Member

  6. Apr 21, 2006 #5
    I had already found that; nothing happens when I plug that into Mathematica. I entered:

    Code (Text):
    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.
     
  7. Apr 23, 2006 #6

    Tide

    User Avatar
    Science Advisor
    Homework Helper

    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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Digital Sums in Mathematica
  1. Mathematica and Sums (Replies: 4)

  2. Mathematica Sums (Replies: 6)

Loading...