Re: FindMinimum

*To*: mathgroup at smc.vnet.net*Subject*: [mg90565] Re: FindMinimum*From*: "David Park" <djmpark at comcast.net>*Date*: Sun, 13 Jul 2008 15:48:05 -0400 (EDT)*References*: <29862167.1215269377863.JavaMail.jakarta@nitrogen.mathforum.org> <g59tvj$ost$1@smc.vnet.net>

You could us the double underline (_ _ instead of _ but without an extra space) to indicate one or more arguments. For example: f[x__?NumberQ] will accept one or more numbers as arguments. And you could use g[{x__}] to indicate a List with one or more elements. You could use Apply (@@) to apply a function without a list to an indefinite list of arguments. f@@{x1, x2, ...} gives f[x1, x2,...] And if you define a function as f[x__] then internally you can use {x} to get the arguments back into a list. -- David Park djmpark at comcast.net http://home.comcast.net/~djmpark/ "pratip chakraborty" <pratip.official at gmail.com> wrote in message news:g59tvj$ost$1 at smc.vnet.net... > Hi, > I am new in Mathematica and have a problem with "FindMinimum". I want to > minimize a multi variable numerical function it looks like: > > MinFun[{a1,a2,...,ak}] > > I also have a code for the gradient computation so I want to use the > gradient option of FindMinimum and supply my gradient function which looks > like: > > GradFun[{a1,a2,...,ak}] > > Now my problem is in the fact that FindMinimum accepts the cost function > and > the supplied gradient if and only if they are of the form: > > MinFun[a1,a2,...,ak] > GradFun[a1,a2,...,ak] > > But I can not every time write a cost function like: > > MinFun[a1_?NumericQ,a2_?NumericQ,...,ak_?NumericQ] > GradFun[a1_?NumericQ,a2_?NumericQ,...,ak_?NumericQ] > > because my k can vary among the set of positive integers so I defined my > cost function with modified test for the argument as > > MinFun[a_?(VectorQ[#,NumericQ]&)] > GradFun[a_?(VectorQ[#,NumericQ]&)] > > But I dont know how to define a function > f[a1_?NumericQ,...,a2000_?NumericQ]:=Block[ > {..}, > ... > ] > other than writing so many arguments manualy. > I tried a wraper like > g[{a_}]:=f[a] > But an error occurs saying the shapes dont match. > Hope some one can help me. > > Pratip > >