MATLAB decomposing numbers (armstrong numbers)

  • Context: MATLAB 
  • Thread starter Thread starter pslarsen
  • Start date Start date
  • Tags Tags
    Matlab Numbers
Click For Summary
SUMMARY

This discussion focuses on decomposing numbers to identify Armstrong numbers using MATLAB. The user, Peter, seeks an optimized method for this task, providing an example of the number 57483920 and its decomposition into digits. He defines an Armstrong number as one where the sum of its digits raised to the power of the number of digits equals the number itself, citing examples such as 370 and 153. Peter has created a function but is looking for enhancements to improve its efficiency.

PREREQUISITES
  • Understanding of MATLAB programming
  • Familiarity with number theory concepts, specifically Armstrong numbers
  • Basic knowledge of function optimization techniques
  • Experience with MATLAB file management and execution
NEXT STEPS
  • Research MATLAB vectorization techniques for performance improvement
  • Explore MATLAB's built-in functions for number manipulation
  • Learn about algorithm optimization strategies specific to numerical computations
  • Investigate the implementation of recursive functions in MATLAB
USEFUL FOR

Mathematics enthusiasts, MATLAB programmers, and developers interested in optimizing numerical algorithms will benefit from this discussion on Armstrong numbers.

pslarsen
Messages
23
Reaction score
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
 
Physics news on Phys.org
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
 

Attachments

Similar threads

  • · Replies 3 ·
Replies
3
Views
5K
Replies
7
Views
2K
  • · Replies 80 ·
3
Replies
80
Views
10K
  • · Replies 32 ·
2
Replies
32
Views
5K
Replies
0
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 10 ·
Replies
10
Views
4K
  • · Replies 6 ·
Replies
6
Views
2K
Replies
6
Views
2K