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
  • Subject: [mg100404] Re: Indexed Slot in a Rule - How to do it??
  • From: Alexei Boulbitch <Alexei.Boulbitch at>
  • Date: Tue, 2 Jun 2009 06:49:16 -0400 (EDT)

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

eqs = {0, 5*x1, 1, 10*x3, 3*x2};

convert this to:

indexedeqs = {0, 5*#[[1]], 1, 10*#[[3]], 3*#[[2]]};


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:

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:
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,

Hi, Alan,
try one of these two ways:

In[10]:= T1[q_List] := {0, 5*q[[1]], 1, 10*q[[3]], 3*q[[2]]};

T1[{1, 2, 3}]

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

In[7]:= T2 := {0, 5*#[[1]], 1, 10*#[[3]], 3*#[[2]]} &;

In[9]:= T2[{1, 2, 3}]

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

Best, Alexei

Alexei Boulbitch, Dr., habil.
Senior Scientist

ZAE Weiergewan
11, rue Edmond Reuter
L-5326 Contern

Phone: +352 2454 2566
Fax:   +352 2454 3566


This e-mail may contain trade secrets or privileged, undisclosed or otherwise confidential information. If you are not the intended recipient and have received this e-mail in error, you are hereby notified that any review, copying or distribution of it is strictly prohibited. Please inform us immediately and destroy the original transmittal from your system. Thank you for your co-operation.

  • Prev by Date: Re: The standard deviation of Three fitting parameters is bigger than
  • Next by Date: Re: two questions
  • 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??