MathGroup Archive 2006

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

Search the Archive

Re: Function of several variables

  • To: mathgroup at
  • Subject: [mg72203] Re: Function of several variables
  • From: "Ray Koopman" <koopman at>
  • Date: Thu, 14 Dec 2006 05:49:28 -0500 (EST)
  • References: <eljaik$7dv$>

tlhiv wrote:
> I have created a list of variables that I would like to make a function
> in terms of by
> M = 4;
> X = Table[Subscript[x, i], {i, 1, M}]
> Now I would like to make a function f that is a function of each of
> these M variables.  If I were manually create this function without
> taking advantage of iterators, I would do something like
> f[Subscript[x,1]_,Subscript[x,2]_,Subscript[x,3]_,Subscript[x,4]_] =
> 1/(Subscript[x,1]+Subscript[x,2]+Subscript[x,3]+Subscript[x,4])
> However, my plan is to significantly increase M, and therefore I don't
> want to have to manually define f in this way.  I would like to define
> it in terms of the elements of X and use the Sum in the function
> definition.  In the end I'm going to be solving an optimization problem
> where I try to find the "optimal" choice for these elements of X.  Can
> someone offer a method for accomplishing this function definition?
> Thanks,
> --
> Troy Henderson
> Assistant Professor
> Department of Mathematical Sciences
> United States Military Academy

Here's a toy example, that minimizes Sum[(x[i]-i)^2,{i,n}]
from a (poor) random start:

In[1]:= ranger[n_] := Block[{v, x}, v = Array[x,n];
                            FindMinimum[#.#&[v - Range@n],
In[2]:= ranger[4]

Out[2]= {0., {x[1] -> 1., x[2] -> 2., x[3] -> 3., x[4] -> 4.}}

This gives a list of the minimizing values:

In[3]:= %[[2,All,2]]

Out[3]= {1.,2.,3.,4.}

  • Prev by Date: Re: How to solve this equation?
  • Next by Date: RE: Mathematica video output without printing frames
  • Previous by thread: Re: Re: Function of several variables
  • Next by thread: (Revisited) Intercepting and Controlling Mathematica Exceptions.