MathGroup Archive 1997

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

Search the Archive

Re: mathematica question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg9232] Re: [mg9199] mathematica question
  • From: Allan Hayes <hay at haystack.demon.co.uk>
  • Date: Fri, 24 Oct 1997 01:00:47 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

Tue, 21 Oct 1997 02:03:12 -0400
Tom <toad at planet.eon.net>
[mg9199] mathematica question

> I have a set of functions that take no inputs, they are called
> q1[],q2[], q3[] and so on.
> How can I get Mathematica to run the correct function given a  
list > of numbers as input.  IE, if I supply the list {1,4,7,8} I  
would
> want Mathematica to run the functions q1[], q4[], q7[] and q8[],
> assuming they were defined.

Tom:

f[i_]:= ToExpression["q"<>ToString[i]<>"[]"]

f[4]
	q4[]

ff[x_List]:=f/@x

ff[{1,2,3}]

	{q1[],q2[],q3[]}
or

ff2[x_List]:= Scan[f,x]
	
Trace[ff2[{1,2,3}],_[]]
	
	{{q1[]},{q2[]},{q3[]}}
	
There are othe possibiities.
	
Allan Hayes
hay at haystack.demon.co.uk
http://www.haystack.demon.co.uk/training.html voice:+44 (0)116 2714198
fax: +44 (0)116 2718642
Leicester,  UK


  • Prev by Date: RE: Horse Race Puzzle (fwd)
  • Next by Date: Re: Help with findroot
  • Previous by thread: Re: mathematica question
  • Next by thread: Re: mathematica question