Re: Turning the elements of a list into the arguments of a function.

*To*: mathgroup at smc.vnet.net*Subject*: [mg8864] Re: [mg8827] Turning the elements of a list into the arguments of a function.*From*: David Withoff <withoff>*Date*: Tue, 30 Sep 1997 20:16:28 -0400*Sender*: owner-wri-mathgroup at wolfram.com

> Hi. I'm sort of new to Mathematica, and Chapter 2.2 in the manual on > Functional Operators and listy things makes my head spin :-) > > I need to be able to convert > f[q, {{a,b}, {c,d}}] into f[q, {a,b}, {c,d}] > > If the problem were to convert f[{{a,b},{c,d}}] into f[{a,b}, {c,d}], I know > I could do this with Apply, as Apply[f, {{a,b},{c,d}}], but having that > first argument is making my life difficult. > > What I am actually trying to do is use FindMinimum with a variable number of > variables, so I tried FindMinimum[expr, Table[{g[i], 0}, {i, 1, n}] sort of > thing, but this puts all the variables and their starting values in one huge > list. > > Does anyone have some ideas on how to solve this one? > > Thanks muchly, > Scott Morrison > scott at morrison.fl.net.au The first operation that you mentioned can be done using FlattenAt: In[3]:= FlattenAt[f[q, {{a,b}, {c,d}}], 2] Out[3]= f[q, {a, b}, {c, d}] You can also use FlattenAt in the second operation that you mentioned, but there are several other ways to do that which might work out better for you, such as In[4]:= FindMinimum[x[1]^2 + x[2]^2 + 1, Evaluate[Sequence @@ Table[{x[i], 1}, {i, 2}]]] -12 -12 Out[4]= {1., {x[1] -> -5.7581 10 , x[2] -> -5.7581 10 }} Dave Withoff Wolfram Research