Re: Re: Numerical Optimization involving equation solving

*To*: mathgroup at smc.vnet.net*Subject*: [mg56061] Re: [mg56005] Re: [mg55969] Numerical Optimization involving equation solving*From*: DrBob <drbob at bigfoot.com>*Date*: Thu, 14 Apr 2005 08:56:04 -0400 (EDT)*References*: <200504120926.FAA27654@smc.vnet.net> <200504130510.BAA09570@smc.vnet.net>*Reply-to*: drbob at bigfoot.com*Sender*: owner-wri-mathgroup at wolfram.com

By the way, (stuff;Return[ans];) should be simply (stuff;ans) Usually there are local variables (needed only within the function), so you'd have Block[{locals},stuff;ans] or the same using With or Module in place of Block. Blocking the local/temporary variables helps prevent "side-effects" of a function execution. There's no need for Return, Break, Continue, Goto, or Label unless you have a "spagetti-code" addiction you're unwilling to break. The sooner you abandon it, the more you'll get out of Mathematica's functional paradigm. Bobby On Wed, 13 Apr 2005 01:10:42 -0400 (EDT), Chris Chiasson <chris.chiasson at gmail.com> wrote: > try changing the "definition of the f function" so that it "only > accepts numerical arguments". > f[x_?NumericQ]:=(stuff;Return[ans];) > > On Apr 12, 2005 5:26 AM, Brian Rogers <brifry at gmail.com> wrote: >> I need to optimize a function of one variable, say >> f[x_]:=(stuff;Return[ans];). Computing the value of f requires solving >> a (non-linear) system of equations that depend on x, and using this >> solution to compute some other things. >> >> Now, evaluating f at a numerical value of x works just fine, and I can >> even plot f (using Plot[f[x],{x,0,1}]) and eyeball the optimum. By the >> way, f is a very well behaved function--it is typically smooth and >> globally convex. However, what I really want to do is use FindMinimum >> (or NMinimize) to numerically return the optimum. When I use either of >> these built-in functions, they crash. I believe that they are first >> trying to evaluate f[x] symbolically--which would understandably cause >> it to crash because the system of equations doesn't have a closed form >> solution in x. >> >> I've tried using the "Compiled" option with no luck. How can I force >> FindMinimum to use a purely numerical procedure to optimize my >> function? >> >> Any help is greatly appreciated, and please copy any reply to >> brifry at gmail.com. >> Thanks! >> >> > > -- DrBob at bigfoot.com

**References**:**Numerical Optimization involving equation solving***From:*"Brian Rogers" <brifry@gmail.com>

**Re: Numerical Optimization involving equation solving***From:*Chris Chiasson <chris.chiasson@gmail.com>