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

MATLAB decomposing numbers (armstrong numbers)

  1. Nov 12, 2009 #1
    Hello.
    I want to solve the problem with armstrong numbers. Is there a smart way to decompose a number in MATLAB?

    E.g. 57483920 = [5 7 4 8 3 9 2 0]

    I want to find the numbers which has the following property:

    Let k be the number of digits in a number, n, and d1,d2,d3,d4... be the digits of n.
    Say n=370. Then k=3 and d1=3, d2=7 and d3=0.
    Now 3^3+7^3+0^3=370. So 370 is an Armstrong number.
    Armstrong iff n=d1^k+d2^k+d3^k+d4^k+..

    Another Armstrong number is 153 because 1^3+5^3+3^3 = 153
     
  2. jcsd
  3. Nov 13, 2009 #2
    Okay, I have written my own function but it can surely be optimized. The first 20 Armstrong numbers are:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    153
    370
    371
    407
    1634
    8208
    9474
    54748
    92727
    93084
    548834

    Enjoy,
    Peter.

    PS: To run the programme place both MATLAB-files in the same directory and run faktor2.m
     

    Attached Files:

Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: MATLAB decomposing numbers (armstrong numbers)
  1. Matlab - number format (Replies: 4)

Loading...