Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Re: lists of variables

  • To: mathgroup at smc.vnet.net
  • Subject: [mg58230] Re: lists of variables
  • From: dh <dh at metrohm.ch>
  • Date: Thu, 23 Jun 2005 05:34:24 -0400 (EDT)
  • References: <d9630u$q1t$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi Heath,
You already got many answers, but I think the solution to create a 
variable name as a string and using ToExpression  is not the appropriate 
  way to do this.
Array[..] is made for this purpose. But you must know how to deal with 
it. Especially, you should not use the same name used inside "Array" for 
other purposes. Lets make some examples:
ts=Array[t,{3}]
gives : {t[1], t[2], t[3]}
Do not use the same name on the left side and inside Array, you would 
get an infinit recursion. Now set up any function you like. If you 
define the arguments as a list, you may directly use ts:
F[{x1_,x2_,x3_}]:=Cos[x1+x2-x3];
you can now say:
F[ts]
giving: Cos[t[1] + t[2] - t[3]] as requested.
if F is defined with three arguments like:
F[x1_,x2_,x3_].=...
you would use Sequence:
F[Sequence[ts]]

If you want to give numerical values, e.g.
t[1]=0.1; t[2]=0.2; t[3]=0.3;
F[ts] would give:
Cos[0.1+0.2-0.3] -> 1.

sincerely, Daniel

Heath Gerhardt 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]]
> 
> thanks in advance
> Heath
> 


  • Prev by Date: Re: a small problem from a newbee...
  • Next by Date: Synergetics section 260.42
  • Previous by thread: Re: lists of variables
  • Next by thread: Re: lists of variables