lists of variables

• To: mathgroup at smc.vnet.net
• Subject: [mg58252] lists of variables
• From: Paul Abbott <paul at physics.uwa.edu.au>
• Date: Fri, 24 Jun 2005 03:28:42 -0400 (EDT)
• Organization: The University of Western Australia
• Sender: owner-wri-mathgroup at wolfram.com

```Heath Gerhardt <heathgerhardt at hotmail.com> wrote:

> I need to make lists of variables, for example
>
> {t1,t2,t3}
>
> but have not been able to figure out how to make Mathematica do this.
> Tried using
>
> Array[t,3]
>
> which gives
>
> {t[1],t[2],t[3]}
>
> but then I don't know how to set the t[i]'s in expressions similar to
>
> F[t[1]_,t[2]_,t[3]_]:=Cos[t[1]+t[2]-t[3]]

Apart from the suggestions of other respondents, there is another
approach to this sort of problem. If your goal is to define a function
that performs some operation on a list of variables, list operations

f[x_List] := Cos[x[[1]] + x[[2]] - x[[3]]] /; Length[x]==3

Then both

f[{t1, t2, t3}]

and

f[Array[t, {3}]]

work. Indeed you can also use subscripted variables as arguments.

Moreover, if your list operations treat all elements on an equal
footing, then the definitions are simpler. For example, defining

g[x_List] := Cos[Tr[x]]

then your F is just g[t1, t2, -t3].

Cheers,
Paul

--
Paul Abbott                                      Phone: +61 8 6488 2734
School of Physics, M013                            Fax: +61 8 6488 1014
The University of Western Australia         (CRICOS Provider No 00126G)
AUSTRALIA                               http://physics.uwa.edu.au/~paul
http://InternationalMathematicaSymposium.org/IMS2005/

```

• Prev by Date: Re: Numerical solution of quadratic equations set.
• Next by Date: Re: General 3-state stochastic matrix
• Previous by thread: Re: Re: lists of variables
• Next by thread: Re: lists of variables