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 =
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.
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 =
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 xy
A = [x^2*y + x^3, (x + y)^2, x^2 + x*y^2 + x*y + x + y^3 + y];
L = lcm(A)
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.
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.
The lcm function now always returns a real positive integer for
an input array that contains real positive and negative integers. For example, this
code returns
256.
L = lcm(sym([256 -128]))
L =
256
In previous releases, if the input array contains an odd number
of real negative integers, then lcm returns a real negative
integer. For example, the same code returns -256 in previous
releases.
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.