MathGroup Archive 2010

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

Search the Archive

Re: Question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg110272] Re: Question
  • From: David Carraher <david_carraher at terc.edu>
  • Date: Fri, 11 Jun 2010 02:09:31 -0400 (EDT)
  • References: <huntc8$bka$1@smc.vnet.net> <201006101210.IAA02601@smc.vnet.net>

Why not use...?

In[1]:= Array[x, 10]

Out[1]= {x[1], x[2], x[3], x[4], x[5], x[6], x[7], x[8], x[9], x[10]}

David C





From:   David Bailey <dave at removedbailey.co.uk>
To:     mathgroup at smc.vnet.net
Date:   06/10/2010 02:39 PM
Subject: [mg110272]        [mg110261] 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

www.dbaileyconsultancy.co.uk



  • References:
    • Re: Question
      • From: David Bailey <dave@removedbailey.co.uk>
  • Prev by Date: Re: O'Reilly Ebook Deal of Day: Mathematica Cookbook ($9.99)
  • Next by Date: Re: O'Reilly Ebook Deal of Day: Mathematica Cookbook ($9.99)
  • Previous by thread: Re: Question
  • Next by thread: Re: Question