[Date Index]
[Thread Index]
[Author Index]
Re: Creating combinations from a group of sets, PART 2
*To*: mathgroup at smc.vnet.net
*Subject*: [mg48747] Re: [mg48739] Creating combinations from a group of sets, PART 2
*From*: Andrzej Kozlowski <akoz at mimuw.edu.pl>
*Date*: Sat, 12 Jun 2004 23:33:36 -0400 (EDT)
*References*: <200406120359.XAA05140@smc.vnet.net>
*Sender*: owner-wri-mathgroup at wolfram.com
On 12 Jun 2004, at 12:59, John Kiehl wrote:
> the recent msg[48679] on combining elements from a group of sets has
> reminded me that I always wanted a Table[] command that would step
> through lists instead of using iterators. For example, my NewTable[ ]
> command would be used something like this:
>
> NewTable[
> (i+j)/
> (m+n),{1,2,3},{5,10.15.20},{3.14,1,414,0.707},{faith,hope,charity}]
>
> Somehow, magically, the first list would be associated with "i", the
> second list with "j", etc...
>
> Of course, all this could be accomplished, by this Mathematica code:
>
> a={1,2,3};
> b={5,10.15.20};
> c={3.14,1,414,0.707};
> d={faith,hope,charity};
>
> Table[ ( a[[i]] + b[[j]] ) / ( c[[m]] + d[[m]]
> ),{i,1,Lengh[a]},{j,1,Length[b]},{m,1,Length[c]},{n,1,Length[d]}]
>
> but that's a lot of typing.
> -----------------------------------------------------------------------
> --------------
> So here's my first attempt at a NewTable[] command using Distribute[]
> as suggested in responses to msg[48679]. It assumes that the first
> expression in NewTable[ ] is a pure function.
>
> Clear[a,b,c,d,e,f,g];
> NewTable[f_,h___]:=f /@ Distribute[{h},List]
>
> and here it is in use:
>
> In[]:=table[#[[1]] + #[[2]]^#[[3]] & , {a, b, c}, {d, e}, {f, g}]
> Out[]:={a + d^f, a + d^g, a + e^f, a + e^g, b + d^f, b + d^g, b + e^f,
> b + e^g, c + d^f, c + d^g, c + e^f, c + e^g}
>
>
> This has the nice advantage of working with any number of lists. I
> just wish I could get rid of all the double bracket typing!
>
> -----------------------------------------------------------------------
> ------------------
> I'm not sure I can even figure out how WRI has programmed the regular
> Table[] command. What would the code for Table[] look like?
>
> john kiehl
>
>
>
>
But you can already do this without any additional functions and double
brackets. Taking your last example:
In[2]:=
Flatten[Outer[#1 + #2^#3 & , {a, b, c}, {d, e}, {f, g}]]
Out[2]=
{a + d^f, a + d^g, a + e^f, a + e^g, b + d^f, b + d^g,
b + e^f, b + e^g, c + d^f, c + d^g, c + e^f, c + e^g}
Andrzej Kozlowski
Chiba, Japan
http://www.mimuw.edu.pl/~akoz/
Prev by Date:
**RE: Creating combinations from a group of sets, PART 2**
Next by Date:
**Re: Integral of a bivariate function**
Previous by thread:
**Creating combinations from a group of sets, PART 2**
Next by thread:
**RE: Creating combinations from a group of sets, PART 2**
| |