Discussion:
LCM With Variable Number of Arguments
(too old to reply)
Mark Lookabaugh
2003-08-23 12:46:06 UTC
Permalink
Hi,

I have a list of numbers, and I'd like to get the LCM of all the
values in the list. The list isn't always the same length at runtime.

What's the syntax to specify that?

For example:

If I have myList = { 2, 3, 4, 5 }
I'd like to do something like LCM[myList] and get 60.

but that actually returns { 2, 3, 4, 5 } (I guess performing LCM on
each element individually).

How can I get LCM to act on a bunch of values at once?

Thanks for any help,
Mark

--
Mark Lookabaugh
mlookabaugh (at) cox.net
USS Brewton FF-1086 Home Page
http://www.ussbrewton.com
David Park
2003-08-24 08:57:03 UTC
Permalink
Mark,

LCM does not work on lists, but on arguments. Use the Apply function.

LCM @@ {2, 3, 4, 5}
60

list = {1, 2, 6, 5, 3};
LCM @@ list
30

The list can be any length.

David Park
***@earthlink.net
http://home.earthlink.net/~djmp/

From: Mark Lookabaugh [mailto:***@NO_ADS.cox.net]

Hi,

I have a list of numbers, and I'd like to get the LCM of all the
values in the list. The list isn't always the same length at runtime.

What's the syntax to specify that?

For example:

If I have myList = { 2, 3, 4, 5 }
I'd like to do something like LCM[myList] and get 60.

but that actually returns { 2, 3, 4, 5 } (I guess performing LCM on
each element individually).

How can I get LCM to act on a bunch of values at once?

Thanks for any help,
Mark

--
Mark Lookabaugh
mlookabaugh (at) cox.net
USS Brewton FF-1086 Home Page
http://www.ussbrewton.com
Steven Shippee
2003-08-24 08:59:04 UTC
Permalink
Regarding LCM (Least Common Multiple) - it works on various elements, but
they must be in brackets, not parenthesis.

For example, you wanted to act on myList = { 2, 3, 4, 5 }

if you change this to LCM[2, 3, 4, 5 ]
Mathematica will return the answer you expect, 60.

Thanks in advance,

Steven Shippee
***@jcs.mil
(360) 493-8353
Post by Mark Lookabaugh
Hi,
I have a list of numbers, and I'd like to get the LCM of all the
values in the list. The list isn't always the same length at runtime.
What's the syntax to specify that?
If I have myList = { 2, 3, 4, 5 }
I'd like to do something like LCM[myList] and get 60.
but that actually returns { 2, 3, 4, 5 } (I guess performing LCM on
each element individually).
How can I get LCM to act on a bunch of values at once?
Thanks for any help,
Mark
--
Mark Lookabaugh
mlookabaugh (at) cox.net
USS Brewton FF-1086 Home Page
http://www.ussbrewton.com
Carl K. Woll
2003-08-24 09:10:21 UTC
Permalink
Mark,

LCM is expecting to be used as LCM[2,3,4,5] and not LCM[{2,3,4,5}]. So, you
should use Apply (shorthand @@) as follows:

LCM @@ myList

Carl Woll
Physics Dept
U of Washington
Post by Mark Lookabaugh
Hi,
I have a list of numbers, and I'd like to get the LCM of all the
values in the list. The list isn't always the same length at runtime.
What's the syntax to specify that?
If I have myList = { 2, 3, 4, 5 }
I'd like to do something like LCM[myList] and get 60.
but that actually returns { 2, 3, 4, 5 } (I guess performing LCM on
each element individually).
How can I get LCM to act on a bunch of values at once?
Thanks for any help,
Mark
--
Mark Lookabaugh
mlookabaugh (at) cox.net
USS Brewton FF-1086 Home Page
http://www.ussbrewton.com
Dr Bob
2003-08-24 09:20:36 UTC
Permalink
myList = {2, 3, 4, 5};
LCM @@ myList

60

Bobby

On Sat, 23 Aug 2003 08:09:06 -0400 (EDT), Mark Lookabaugh
Post by Mark Lookabaugh
Hi,
I have a list of numbers, and I'd like to get the LCM of all the
values in the list. The list isn't always the same length at runtime.
What's the syntax to specify that?
If I have myList = { 2, 3, 4, 5 }
I'd like to do something like LCM[myList] and get 60.
but that actually returns { 2, 3, 4, 5 } (I guess performing LCM on
each element individually).
How can I get LCM to act on a bunch of values at once?
Thanks for any help,
Mark
--
Mark Lookabaugh
mlookabaugh (at) cox.net
USS Brewton FF-1086 Home Page
http://www.ussbrewton.com
--
***@cox-internet.com
Bobby R. Treat
Loading...