least common (positive) multiple of integers or of polynomials
pp = lcm(p) [pp, fact] = lcm(p)
matrix of polynomials (type 2), or of decimal or encoded integers (types 1 or 8).
a polynomial or a decimal integer: Positive Least Common Multiple of
p
components.
matrix of polynomials, or of decimal integers (type 1), with the size of
p
, such that fact(i)= pp./p(i)
.
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,
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)
.
With polynomials:
--> p = [s , s*(s+1) , s^2-1] 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:
With big integers:
--> 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] V = 1.351D+16 15. --> [pp, fact] = lcm(V) fact = 15. 1.351D+16 pp = 2.027D+17
Version | Description |
6.0.1 | For input integers possibly negative, the returned LCM is now always positive. |
6.0.2 |
|