Re: Turning the elements of a list into the arguments of a function.
- To: mathgroup at smc.vnet.net
- Subject: [mg8857] Re: Turning the elements of a list into the arguments of a function.
- From: Paul Abbott <paul at physics.uwa.edu.au>
- Date: Tue, 30 Sep 1997 20:16:17 -0400
- Organization: University of Western Australia
- Sender: owner-wri-mathgroup at wolfram.com
Scott Morrison wrote: > 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. You need to use Evaluate (because FindMinimum is HoldAll) and Sequence: In[1]:= FindMinimum[g[1]^2-2g[1]+2g[2]^2, Evaluate[Sequence@@Table[{g[i], 0}, {i, 1, 2}]]] Out[1]= {-1., {g[1] -> 1., g[2] -> 0.}} Cheers, Paul ____________________________________________________________________ Paul Abbott Phone: +61-8-9380-2734 Department of Physics Fax: +61-8-9380-1014 The University of Western Australia Nedlands WA 6907 mailto:paul at physics.uwa.edu.au AUSTRALIA http://www.pd.uwa.edu.au/~paul God IS a weakly left-handed dice player ____________________________________________________________________