MathGroup Archive 2010

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

Search the Archive

Re: Question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg110244] Re: Question
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Thu, 10 Jun 2010 08:07:43 -0400 (EDT)
  • Reply-to: hanlonr at cox.net

var = ToExpression[
  Table["x" <> ToString[k], {k, 4}]]

{x1,x2,x3,x4}

Reduce[
  Join[
   Thread[0 < var < 10],
   {Total@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@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 at 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





  • Prev by Date: Re: Question
  • Next by Date: Re: Nonlinear Least Squares lsqnonlin
  • Previous by thread: Re: Question
  • Next by thread: Re: Question