[Date Index]
[Thread Index]
[Author Index]
RE: Creating combinations from a group of sets, PART 2
*To*: mathgroup at smc.vnet.net
*Subject*: [mg48748] RE: [mg48739] Creating combinations from a group of sets, PART 2
*From*: "David Park" <djmp at earthlink.net>
*Date*: Sat, 12 Jun 2004 23:33:37 -0400 (EDT)
*Sender*: owner-wri-mathgroup at wolfram.com
John,
Why don't you use Outer?
a = {1, 2, 3};
b = {5, 10.15.20};
c = {3.14, 1, 414, 0.707};
d = {faith, hope, charity};
Outer[(#1 + #2)/(#3 + #4) &, a, b, c, d]
Also, if you had equal lenght lists, or just wanted to produce a single
level table at irregular values, you could use MapThread, or use a List in
an expression.
David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/
From: John Kiehl [mailto:john.kiehl at soundtrackny.com]
To: mathgroup at smc.vnet.net
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
Prev by Date:
**Re: Substitution ignored?**
Next by Date:
**Re: Creating combinations from a group of sets, PART 2**
Previous by thread:
**Re: Creating combinations from a group of sets, PART 2**
Next by thread:
**NDSolve, coupled equations, different number of variables**
| |