MathGroup Archive 2010

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

Search the Archive

Re: Question

On 09/06/10 12:19, 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.
> David

The simple answer is:

myvars=Table[ToExpression["XX" <> ToString[k]], {k, 1, 10}]

However, working with created variable names like that can be quite 
tricky because either they evaluate when you don't want them to, or you 
end up assigning to an expression such as myvars[[5]], rather than the 
variable itself.

For that reason, you may want to present a bit more of your problem so 
as to get a complete solution.

David Bailey

  • Prev by Date: Answer
  • Next by Date: Re: Question
  • Previous by thread: Re: Question
  • Next by thread: Re: Question