Services & Resources / Wolfram Forums / MathGroup Archive

MathGroup Archive 2010

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

Search the Archive

Re: Question

  • To: mathgroup at
  • Subject: [mg110238] Re: Question
  • From: Erik Max Francis <max at>
  • Date: Thu, 10 Jun 2010 08:06:37 -0400 (EDT)
  • References: <huntc8$bka$>

David Lengacher wrote:
> How can you create a set of variables: x1 to xn  using the Table, or some
> similar function?    I need a large list of variables to use in a linear
> program and so far have to type them out manually."

You can stitch them together with ToString and Symbol:

In[11]:= Table[Symbol["x" <> ToString[i]], {i, 1, 5}]

Out[11]= {x1, x2, x3, x4, x5}

But better yet, there's no real reason to do this in the first place. 
Mathematica's fully symbolic, even with unknown functions, so you really 
shouldn't need to make them into individual symbols in the first place:

In[12]:= Table[x[i], {i, 1, 5}]

Out[12]= {x[1], x[2], x[3], x[4], x[5]}

In[13]:= x[1] = 2;
x[2] = 3;
x[1] + x[2]

Out[15]= 5

Erik Max Francis && max at &&
  San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis
   I wonder if this grief will ever let me go
    -- Sade

  • Prev by Date: Re: Nonlinear Least Squares lsqnonlin
  • Next by Date: Re: Push to clipboard?
  • Previous by thread: Re: Question
  • Next by thread: Nonlinear Least Squares lsqnonlin