Re: Cascaded (Multi-range) Iterators?
- To: mathgroup at smc.vnet.net
- Subject: [mg79072] Re: Cascaded (Multi-range) Iterators?
- From: Peter Pein <petsie at dordos.net>
- Date: Tue, 17 Jul 2007 03:30:47 -0400 (EDT)
- References: <f7f2lh$o64$1@smc.vnet.net>
AES schrieb: > Seems like a very useful (and feasible?) (and not too difficult) > extension to the Iterator concept for Tables, etc., would be a cascaded > or multi-range Iterator, e.g. something like > > Table[ f[x], { {x, 0, 1, 0.1}, {x, 2, 10}, {x, 20, 100, 10} } ] > > I often have need for a "different step sizes over different ranges" > capability like this, and have to resort to workarounds to achieve it. > > [Apologies if my searches in the Help files have missed something that > already does this.] > Hi, there are anonymous functions and Apply[f,lst] (short: f @@@ lst): In[1]:= {t1, t2, t3} = Table[f[x, y], ##1] & @@@ {{{x, 3}}, {{y, 2, 5}}, {{x, -1, 1}, {y, 5, 3, -1}}}; In[2]:= t2 Out[2]= {f[x, 2], f[x, 3], f[x, 4], f[x, 5]} In[3]:= t3 Out[3]= {{f[-1, 5], f[-1, 4], f[-1, 3]}, {f[0, 5], f[0, 4], f[0, 3]}, {f[1, 5], f[1, 4], f[1, 3]}} In[4]:= t1 Out[4]= {f[1, y], f[2, y], f[3, y]} Hope that helps, Peter P.S.: if it is more convenient, you can write this as: {t1,t2,t3}=Apply[Function[rng, Table[f[x,y],rng]], {{{x, 3}}, {{y, 2, 5}}, {{x, -1, 1}, {y, 5, 3, -1}}}, {1}];