MathGroup Archive 2009

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

Search the Archive

Re: Indexed Slot in a Rule - How to do it??

  • To: mathgroup at smc.vnet.net
  • Subject: [mg100334] Re: [mg100289] Indexed Slot in a Rule - How to do it??
  • From: "Scot T. Martin" <smartin at seas.harvard.edu>
  • Date: Mon, 1 Jun 2009 07:08:48 -0400 (EDT)
  • References: <200905311034.GAA16834@smc.vnet.net>

Alan, I'm not sure I fully understand your question. Is below what you're 
after?


In[1]:= func[list_List] := {0, 5 list[[1]], 1, 10 list[[3]], 3 list[[2]]}

In[2]:= func[{1, 2, 3}]

Out[2]= {0, 5, 1, 30, 6}

In[3]:= func[{x1, x2, x3}]

Out[3]= {0, 5 x1, 1, 10 x3, 3 x2}



On Sun, 31 May 2009, Alan wrote:

> Here's the problem.  Convert a vector (list) with symbol names into
> indexed slots.  I'm doing this so that I can turn the vector into
> function that takes a list.  Here's an example of the desired
> behavior:
>
> eqs = {0, 5*x1, 1, 10*x3, 3*x2};
>
> convert this to:
>
> indexedeqs = {0, 5*#[[1]], 1, 10*#[[3]], 3*#[[2]]};
>
> T[q_]:=indexedeqs;
>
> T[{1,2,3}] = {0,5,1,30,6}
>
> I can't for the life of me figure out how to do this.  I've been
> performing meta-Mathematica all week.  Here's the closest I've come:
>
> xvars={x1,x2,x3};
> MapIndexed[Rule[#1, #[[First@#2]]] &, xvars]
>
> But, this treats the second # literally, and puts in the current item
> from xvars.  I need a way for the second # to just be # without it
> really taking a value.
>
> So, I tried doing it as a string:
> xvars={x1,x2,x3};
> MapIndexed[Rule[#1, "#[[" <> ToString[First@#2] <> "]]"] &, xvars]
>
> And this creates a rule that looks correct, but, its right hand side
> of the rule is a string instead of an expression.
>
> I can't figure this out!!!  Any help is greatly appreciated.
>
> All the best,
> Alan
>
>


  • Prev by Date: Re: two questions
  • Next by Date: Re: MatrixForm affects values instead of only printing
  • Previous by thread: Re: Indexed Slot in a Rule - How to do it??
  • Next by thread: Re: Indexed Slot in a Rule - How to do it??