From: telefunkenvf14 on
On Jun 9, 6:19 am, David Lengacher <dclengac...(a)gmail.com> wrote:
> How can you create a set of variables: x1 to xn using the Table, or so me
> 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

I think what you want is Unique[]:

In[1]:= Unique["x"]

Out[1]= x1

You can use the Table[] command to generate x number of unique
variables, say:

In[2]:= Table[Unique["x"], {10}]

Out[2]= {x2, x3, x4, x5, x6, x7, x8, x9, x10, x11}

(And note that the generated variables are in fact unique.)

-RG

From: Simon on
On Jun 9, 7:19 pm, David Lengacher <dclengac...(a)gmail.com> wrote:
> How can you create a set of variables: x1 to xn using the Table, or so me
> 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

Hi David,

Here's a simple example pulled from the documentation center:

Table[Symbol["x" <> ToString[i]], {i, 5}]
{x1, x2, x3, x4, x5}

Of course you could also use Table[x[i],{i,1,5}] or
Table[Subscript[x,i],{i,1,5}], they all have advantages and
disadvantages.

Simon

From: David Bailey on
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

From: David Carraher on
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(a)removedbailey.co.uk>
To: mathgroup(a)smc.vnet.net
Date: 06/10/2010 02:39 PM
Subject: 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