Least Common Multiple Set
I wanted to find the least common multiple of a group of more than two numbers. Matlab's built in lcm function does not have this capability. It accepts two integer inputs, but cannot handle more. So I wrote lcms. lcms uses the prime factorization method to determine the least common multiple of a set of numbers. It is pretty simple.
z = lcms(numberArray)
This function accepts any n-dimensional array of natural numbers as input (Zeros do not change the output of the program).
Example usage of lcms:
>> lcms([1 2 3 4 6 8 12 24])
ans =
24
>> A = [5 6; 8 10; 12 14]
A =
5 6
8 10
12 14
>> lcms(A)
ans =
840
----
Having a 0 in your input array will not affect the program.
example:
lcms([0 1 2 3]) returns a 6.
lcms([1 2 3]) also returns a 6.
Having negative numbers or non-integer types in your input error will result in an error message.
example:
lcms([2.5 3 2 8]) results in an error.
lcms([5 2 -3 1]) results in an error.
Cita come
Josh (2025). Least Common Multiple Set (https://it.mathworks.com/matlabcentral/fileexchange/24670-least-common-multiple-set), MATLAB Central File Exchange. Recuperato .
Compatibilità della release di MATLAB
Compatibilità della piattaforma
Windows macOS LinuxCategorie
- MATLAB > Mathematics > Elementary Math >
Tag
Riconoscimenti
Ispirato: N-argument least common multiple calculator with arbitrary precision
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Scopri Live Editor
Crea script con codice, output e testo formattato in un unico documento eseguibile.
