From: David Lengacher on 9 Jun 2010 07:19 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
From: Erik Max Francis on 10 Jun 2010 08:06 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(a)alcyone.com && http://www.alcyone.com/max/ 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
From: Bob Hanlon on 10 Jun 2010 08:07 var = ToExpression[ Table["x" <> ToString[k], {k, 4}]] {x1,x2,x3,x4} Reduce[ Join[ Thread[0 < var < 10], {Total(a)var == 12, Times @@ var == 36, Less @@ var}], var, Integers] // ToRules {x1->1,x2->2,x3->3,x4->6} However, it is much easier to use indexed variables programmatically var = Array[x, 4] {x(1),x(2),x(3),x(4)} Reduce[ Join[ Thread[0 < var < 10], {Total(a)var == 12, Times @@ var == 36, Less @@ var}], var, Integers] // ToRules {x(1)->1,x(2)->2,x(3)->3,x(4)->6} Bob Hanlon ---- David Lengacher <dclengacher(a)gmail.com> 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
From: Bill Rowe on 10 Jun 2010 08:07 On 6/9/10 at 7:19 AM, dclengacher(a)gmail.com (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. Here are two ways to do what you want vars=Table[ToExpression["x"<>ToString@n],{n,10}] vars=ToExpression["x"<>ToString[#]&/@Range[10]]
From: M.Roellig on 10 Jun 2010 08:08
On 9 Jun., 13:19, 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, Is this what you are loking for? Table[ToExpression["A" <> ToString[i]], {i, 1, 10}] Markus |