N-argument least common multiple calculator with arbitrary precision

Version 1.5.0.0 (985 Bytes) by Shawn Divitt
This function returns the least common multiple of the set of integers passed to it.
168 Downloads
Updated 4 Nov 2014

View License

This function returns the least common multiple of the set of integers passed to it. The number of inputs can be very large. The function outputs the exact lcm integer. For instance, lcm(1,2,...,1000) is approximately 7.12e432 and vlcm will give all 433 digits. This function is an improvement over the function referenced below in that it uses the "vpa" routine built into MATLAB in order to give arbitrary precision.
usage: output = vlcm(M);
Here, M is the vector of integers for which the lcm is to be calculated.
In the first example we will calculate lcm(1,2,...,100):
>>vlcm(1:100)
ans =
69720375229712477164533808935312303556800
To get the number to 10 significant digits in scientific notation use vpa:
>> vpa(ans,10)
ans =
6.972037523e40
For another example we will calculate lcm(1,2,...,10000). This is impossible using the function referenced below. The number has 4349 digits so we will use scientific notation for brevity. We have:
>> vpa(vlcm(1:10000),10)
ans =
5.79333967e4348

The image is of the second Chebyshev function, which is given by log10(lcm(1,...,n)) and was calculated using this function

Cite As

Shawn Divitt (2024). N-argument least common multiple calculator with arbitrary precision (https://www.mathworks.com/matlabcentral/fileexchange/48312-n-argument-least-common-multiple-calculator-with-arbitrary-precision), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2012b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.5.0.0

Fixed the title.

1.4.0.0

Added a better and more descriptive image.

1.3.0.0

Replaced the uint8 with uint32 in order to increase the number of allowable digits in the answer.

1.2.0.0

fixed an issue with small integers

1.1.0.0

added the requirement of the symbolic toolbox

1.0.0.0