MathGroup Archive 2005

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

Search the Archive

Re: lists of variables


In article <d9gb4h$sud$1 at smc.vnet.net>, "Ray Koopman" <koopman at sfu.ca> 
wrote:

> dh wrote:
> > Hi Heath,
> > You already got many answers, but I think the solution to create
> > a variable name as a string and using ToExpression  is not the
> > appropriate way to do this.
> > Array[..] is made for this purpose.
> 
> I agree that using ToExpression to construct code is awkward and tends
> to obscure what the code is, but for functions such as Minimize, that
> require names of variables in their calling sequence, how else would
> you handle problems in which the number of variables is not fixed?

I'm not sure that I follow you. You can pass the necessary variables to 
such functions. For example, here is a function that generates a random 
polynomial in n variables:

 f[x_List] := Plus @@ Apply[Times, 
    Outer[Plus, x, Table[Random[Integer, {-5, 5}], {Length[x]}]], {1}]

For example,

  SeedRandom[1]

  g = f[{x,y}]

  h = f[{x,y,z}]

Here is a routine that finds the mimimum over a specified domain.

  Minimize[{g, Thread[-2 < Variables[g] < 2]} , Variables[g]]

  Minimize[{h, Thread[-2 < Variables[h] < 2]} , Variables[h]]

And here is a routine for numerical minima:

  Nmin[f_, {x_List, a_List}] := 
   FindMinimum[f, Evaluate[Sequence @@ Transpose[{x, a}]]]

  Nmin[g, {Variables[g], {0,1}}]

  Nmin[h, {Variables[h], {0,1,2}}]

Of course, you cannot use Variables if there are other parameters in the 
functions.

Cheers,
Paul

-- 
Paul Abbott                                      Phone: +61 8 6488 2734
School of Physics, M013                            Fax: +61 8 6488 1014
The University of Western Australia         (CRICOS Provider No 00126G)    
AUSTRALIA                               http://physics.uwa.edu.au/~paul
        http://InternationalMathematicaSymposium.org/IMS2005/


  • Prev by Date: Re: Re: Mathematica program generating sequence ofpoints stalls for no apparent reason.
  • Next by Date: Re: Re: Asking questions
  • Previous by thread: lists of variables
  • Next by thread: mathematica bench mark and hp c8000?