Main Content

lcm

Least common multiple of symbolic numbers and polynomials

Description

L = lcm(A) finds the least common multiple (LCM) of all symbolic elements in A.

example

L = lcm(A,B) finds the least common multiple of A and B.

example

Examples

collapse all

Find the least common multiple of four integers, specified as elements of a symbolic vector.

A = sym([4420 -128 8984 -488]);
L = lcm(A)
L = 9689064320

Alternatively, specify these values as elements of a symbolic matrix.

A = sym([4420 -128; 8984 -488]);
L = lcm(A)
L = 9689064320

Find the least common multiple of five symbolic rational numbers.

A = sym([3/4 7/3 11/2 12/3 33/4])
A = 

(34731124334)

L = lcm(A)
L = 924

Find the least common multiple of three symbolic complex numbers.

A = sym([3 + 1i, -4 - 2i, -5 - 5i]);
L = lcm(A)
L = 10

If you specify two input arguments and at least one of them is nonscalar, lcm finds the least common multiples element-wise

Find the least common multiples for the elements of two matrices. When you specify two nonscalar input arguments, they must be the same size.

A = sym([309 186; 486 224]);
B = sym([558 444; 1024 1984]);
L = lcm(A,B)
L = 

(574741376424883213888)

Find the least common multiples for the elements of matrix A and the value 99. Here, lcm expands 99 into a 2-by-2 matrix with all elements equal to 99.

L = lcm(A,99)
L = 

(101976138534622176)

Find the least common multiple of two univariate polynomials.

syms x
A = x^3 - 3*x^2 + 3*x - 1;
B = x^2 - 5*x + 4;
L = lcm(A,B)
L = x-4x3-3x2+3x-1

Find the least common multiple of three multivariate polynomials. Because there are more than two polynomials, specify them as elements of a symbolic vector.

syms x y
A = [x^2*y + x^3, (x + y)^2, x^2 + x*y^2 + x*y + x + y^3 + y];
L = lcm(A)
L = x3+yx2x2+xy2+xy+x+y3+y

Input Arguments

collapse all

Input value, specified as a symbolic number, variable, expression, function, or a vector or matrix of symbolic numbers, variables, expressions, or functions.

Input value, specified as a symbolic number, variable, expression, function, or a vector or matrix of symbolic numbers, variables, expressions, or functions.

If A and B are nonscalar, they must have the same size. If either A or B is scalar, then lcm expands the scalar into a vector or matrix of the same size as the nonscalar argument, with all elements equal to the corresponding scalar.

Output Arguments

collapse all

Least common multiple, returned as a symbolic number, variable, expression, function, or a vector or matrix of symbolic numbers, variables, expressions, or functions.

Tips

  • Calling lcm with numbers that are not symbolic objects invokes the MATLAB® lcm function.

  • The MATLAB lcm function does not accept rational or complex arguments. To find the least common multiple of rational or complex numbers, convert these numbers to symbolic objects by using sym, and then use lcm.

Version History

Introduced in R2014b

expand all

See Also