MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Variable number of parameters

  • To: mathgroup at smc.vnet.net
  • Subject: [mg33343] RE: [mg33300] Variable number of parameters
  • From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
  • Date: Sat, 16 Mar 2002 01:40:28 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

> -----Original Message-----
> From: Sven Richter
To: mathgroup at smc.vnet.net
> [mailto:Sven.Richter at Xterminator.studfb.unibw-muenchen.de]
> Sent: Thursday, March 14, 2002 8:22 AM
> To: mathgroup at smc.vnet.net
> Subject: [mg33343] [mg33300] Variable number of parameters
> 
> 
> Hi,
> 
> I'd like to have a table with a variable number of parameters, like:
> Table[{m[1], m[2],..., m[n]}, {m[1], minVal, maxVal, step}, 
> {m[2], minVal,
> maxVal, step}, ...,
> {m[n], minVal,  maxVal, step}]
> 
> However, I couldn't find any solution yet...
> Can anyone give me a hint?
> Thx,
> Sven.
> 
> 

Sven,

assuming ...

In[2]:= minVal = 0;
        maxVal = 1;
        step = 1/2;

... (i.e. the same values for start, step, and stop of the iterators
respectively), observe the following steps


In[12]:= Array[{m[#],{m[#],minVal,maxVal,step}}&,3]

In[13]:= Transpose[%]

In[14]:= MapAt[Apply[Sequence,#]&, %,{2}]

In[15]:= TT @@ %
Out[15]=
TT[{m[1], m[2], m[3]}, 
   {m[1], 0, 1, 1/2}, {m[2], 0, 1, 1/2}, {m[3], 0, 1, 1/2}]


So ...

In[16]:=
Table @@ MapAt[Apply[Sequence,#]&,
    Transpose[Array[{m[#],{m[#],minVal,maxVal,step}}&,3]],{2}]

...is a solution to your problem (provided there are no definitions for m)


The general case for a function f in place of List is more difficult, as f
may evaluate prematurely. 

In[17]:= m /: f[m[_], __] := "oops"
In[18]:=
Table[f @@ #1, Evaluate[Sequence @@ #2]] & @@ 
  Transpose[Array[{m[#], {m[#], minVal, maxVal, step}} &, 3]]

No oops'es! Another ("dual") solution would be:

In[21]:=
Table @@ ({Unevaluated[f @@ #1], Sequence @@ #2} &) @@ 
    Transpose[Array[{m[#], {m[#], minVal, maxVal, step}} &, 3]]


Instead of 3 you may take any positive integer for the number of dimensions
of your matrix.

--
Hartmut Wolf



  • Prev by Date: Re: PrimitiveElement doesn't work much.
  • Next by Date: Re: Bug in Simplify?
  • Previous by thread: Re: Variable number of parameters
  • Next by thread: Independent processes ?