function c = lcm2(x) %LCM2 Least common multiple of all elements. % % LCM2(X) is the least common multiple of all elements in X. % % See also GCD, LCM, GCDALL. % Author: Peter John Acklam % Time-stamp: 2004-09-20 09:38:07 +0200 % E-mail: pjacklam@online.no % URL: http://home.online.no/~pjacklam % Check input arguments. error(nargchk(1, 1, nargin)); if ~isnumeric(x) | ~isreal(x) error( 'Argument must be numeric and real.' ); end if ~isequal( round(x), x ) error( 'Argument must contain integers only.' ); end % Now find least common multiple. n = prod( size(x) ); c = x(1); for i = 1:n if ( x(i) ~= 0 ) c = c/gcd(c,x(i))*x(i); end end