Be the first to rate this file! 17 downloads (last 30 days) File Size: 1.26 KB File ID: #24670

Least Common Multiple Set

by Josh

 

08 Jul 2009 (Updated 10 Jul 2009)

Code covered by the BSD License  

Input a set of numbers as an n-dimension array, get their least common multiple.

Download Now | Watch this File

File Information
Description

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.

MATLAB release MATLAB 7.8 (R2009a)
Zip File Content  
Other Files lcms.m,
license.txt
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Updates
10 Jul 2009

Input is more robust. Now you use any n-dimensional array instead of a row vector.

Error behavior is more clear.

Tag Activity for this File
Tag Applied By Date/Time
least Josh 09 Jul 2009 10:55:31
common Josh 09 Jul 2009 10:55:31
multiple Josh 09 Jul 2009 10:55:31
set Josh 09 Jul 2009 10:55:31
group Josh 09 Jul 2009 10:55:31
more Josh 09 Jul 2009 10:55:31
math Josh 09 Jul 2009 10:55:31
lcms Josh 09 Jul 2009 10:55:31
lcm Josh 09 Jul 2009 10:55:31
matrix Josh 13 Jul 2009 10:08:34
array Josh 13 Jul 2009 10:08:35
vector Josh 13 Jul 2009 10:08:35
least kkk 19 Feb 2010 03:14:09
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com