Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

Re: How to dynamically build a list of rules

  • To: mathgroup at smc.vnet.net
  • Subject: [mg109263] Re: How to dynamically build a list of rules
  • From: Ingolf Dahl <ingolf.dahl at physics.gu.se>
  • Date: Mon, 19 Apr 2010 06:13:58 -0400 (EDT)
  • Organization: University of Gothenburg
  • References: <201004190809.EAA10213@smc.vnet.net>
  • Reply-to: <ingolf.dahl at physics.gu.se>

You first define your list of names, say by

namelist = 
 Table[ToExpression[StringJoin["name", ToString[i]]], {i, 1, 10}] 

then you make your rule list by

subs = (#1 -> SomeFunction[#1]) & /@ namelist

Look at "Map" (for /@) and "Function" (for #1 and &) in the Mathematica help
if you do not recognize the notation

Best regards

Ingolf Dahl
Sweden
ingolf.dahl at telia.com


-----Original Message-----
From: janitor048 [mailto:janitor048 at googlemail.com] 
Sent: den 19 april 2010 10:10
To: mathgroup at smc.vnet.net
Subject: [mg109263] [mg109136] How to dynamically build a list of rules

Hi there!

I need a somewhat larger list of substitution rules along the line of

subs = { name1 -> SomeFunction[name1], name2 ->
SomeFunction[name2], ... , nameN -> SomeFunction[nameN]}

Obviously typing that by hand can become a little annoying. So I would
like to have that list created dynamically, via Table[ ... ] or
something the like.
The problem is, I can't figure out the correct syntax for this task.
"name1" etc. are just, well, names (variable names to be specific).
Unfortunately I haven't been able to find a solution on the web so
far. Any suggestions?

Cheers,
Oliver



  • Prev by Date: Re: integrate log*sinc
  • Next by Date: Re: cant free ram..
  • Previous by thread: How to dynamically build a list of rules
  • Next by thread: NIntegrate Confusion