[Date Index]
[Thread Index]
[Author Index]
RE: Number Combining/Wheeling
*To*: mathgroup at smc.vnet.net
*Subject*: [mg25147] RE: [mg25108] Number Combining/Wheeling
*From*: "David Park" <djmp at earthlink.net>
*Date*: Sun, 10 Sep 2000 21:25:41 -0400 (EDT)
*Sender*: owner-wri-mathgroup at wolfram.com
Clay,
Sometimes, in questions like this, it helps to give a simple example so we
know what you mean by combination. Still, you can probably do what you wish
with Outer which forms all possible combinations of two lists.
Here is an example. Let r be the function which "combines" the two numbers
and let the set of numbers be:
list = {1, 2, 3};
Outer forms all combinations of the numbers under r, as a matrix, and
Flatten flattens the matrix to a list.
Outer[r, list, list]
comb = Flatten[%]
{{r[1, 1], r[1, 2], r[1, 3]}, {r[2, 1], r[2, 2], r[2, 3]}, {r[3, 1], r[3,
2],
r[3, 3]}}
{r[1, 1], r[1, 2], r[1, 3], r[2, 1], r[2, 2], r[2, 3], r[3, 1], r[3, 2],
r[3, 3]}
If you just want the pairs of numbers, change r to List.
comb /. r -> List
{{1, 1}, {1, 2}, {1, 3}, {2, 1}, {2, 2}, {2, 3}, {3, 1}, {3, 2}, {3, 3}}
If you want all possible sums of the two numbers, change r to Plus. You can
use Union to eliminate duplicates.
comb /. r -> Plus
Union[%]
{2, 3, 4, 3, 4, 5, 4, 5, 6}
{2, 3, 4, 5, 6}
If you want all possible products of the two numbers, change r to Times and
use Union to eliminate duplicates.
comb /. r -> Times
Union[%]
{1, 2, 3, 2, 4, 6, 3, 6, 9}
{1, 2, 3, 4, 6, 9}
Of course, this may not be what you had in mind. Perhaps what you may have
in mind is to find all possible subsets of the set of numbers. In that case
you can use the Combinatorica package.
Needs["DiscreteMath`Combinatorica`"]
BinarySubsets[list]
{{}, {1}, {2}, {1, 2}, {3}, {1, 3}, {2, 3}, {1, 2, 3}}
I would consider this problem to be one stage above beginner material for
Mathematica. You will certainly need to be familiar with how lists operate
and are manipulated, and how functions and expressions work.
David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/
> -----Original Message-----
> From: Clay [mailto:clayo at cox-internet.com]
To: mathgroup at smc.vnet.net
>
> Help...I'm trying to figure out how create an algorithm that will
> combine a
> given set of numbers into all (or some) possible combinations. Can anyone
> offer a place to start? ......Please be gentle, I'm new to Mathematica.
> Thanks.
> Clay
Prev by Date:
**RE: Displaying Mixed Numbers**
Next by Date:
**what are some good web sites for learning more about programming mathematica for a programmer who's relearning his math...**
Previous by thread:
**Re: Number Combining/Wheeling**
Next by thread:
**Displaying Mixed Numbers**
| |