lcm
least common (positive) multiple of integers or of polynomials
Syntax
pp = lcm(p) [pp, fact] = lcm(p)
Arguments
 p
matrix of polynomials (type 2), or of decimal or encoded integers (types 1 or 8).
 pp
a polynomial or a decimal integer: Positive Least Common Multiple of
p
components. fact
matrix of polynomials, or of decimal integers (type 1), with the size of
p
, such thatfact(i)= pp./p(i)
.
Description
pp=lcm(p)
computes the LCM pp
of p
components.
If p
are polynomials, pp
is a polynomial and
fact
is also a matrix of polynomials.
If p
is a set of integers,
 if they are encoded integers, they are then converted into decimal integers before processing.
 Any int64 or uint64 input integers > 2^53 will be truncated and lcm() will return a wrong result.
 If some of them are negative, the returned value
pp
of their LCM is always positive.
The least common multiple of an array p
of real numbers can be
obtained by converting it to a polynomial before calling lcm
,
through p = inv_coeff(p, 0)
.
Examples
With polynomials:
s = %s; p = [s , s*(s+1) , s^21] [pp, fact] = lcm(p) p .* fact == pp
> p = [s , s*(s+1) , s^21] p = 2 2 s s +s 1 +s > [pp, fact] = lcm(p) fact = 2 1 +s 1 +s s pp = 3 s +s > p .* fact == pp ans = T T T
With encoded integers:
// Prime numbers: 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 V = int16([2*3 3*7 ; 7*5 3*5]) [pp, fact] = lcm(V)
> V = int16([2*3 3*7 ; 7*5 3*5]) V = 6 21 35 15 > [pp, fact] = lcm(V) pp = 210. fact = 35. 10. 6. 14.
With decimal integers:
V = [2*3 3*7 ; 7*5 3*5] [pp, fact] = lcm(V)
With big integers:
V = [3*2^51 , 3*5] [pp, fact] = lcm(V) // OK
> V = [3*2^51 , 3*5] V = 6.755D+15 15. > [pp, fact] = lcm(V) fact = 5. 2.252D+15 pp = 3.378D+16
When the numerical encoding is overflown, truncature occurs and results turn wrong:
V = [3*2^52 , 3*5] [pp, fact] = lcm(V)
> V = [3*2^52 , 3*5] V = 1.351D+16 15. > [pp, fact] = lcm(V) fact = 15. 1.351D+16 pp = 2.027D+17
See also
History
Version  Description 
6.0.1  For input integers possibly negative, the returned LCM is now always positive. 
6.0.2 

Comments
Add a comment:
Please login to comment this page.