Re: NMinimize problem: fct minimized uses FindRoot
- To: mathgroup at smc.vnet.net
- Subject: [mg123558] Re: NMinimize problem: fct minimized uses FindRoot
- From: Bob Hanlon <hanlonr357 at gmail.com>
- Date: Sun, 11 Dec 2011 03:47:01 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <201112101227.HAA19219@smc.vnet.net>
Since myNumFct uses numeric techniques, restrict it to numeric arguments. Return is unnecessary here. Syntax for NMinimize does not include initial estimate. MyNumFct[optvar_?NumericQ] := Module[ {inteq, n}, inteq[x_] := (Sin[x] + Cos[x]/2)/optvar; n = n /. FindRoot[inteq[n], {n, 0.1}]; n + Sin[optvar]] NMinimize[{MyNumFct[var], 0 <= var <= 6}, var] {-1.46365, {var -> 4.71239}} Bob Hanlon On Sat, Dec 10, 2011 at 7:27 AM, Doug Tinkham <dtinkham at live.ca> wrote: > Hello > > I'm using NMinimize and FindMinimum to minimize a function that uses > FindRoot when calculating it's value. The problem is that the equation > that FindRoot is used on uses the variable that is being optimized, and > Mathematica appears to be forcing the variable that is being optimized > to remain symbolic in the FindRoot call, and this leads to recursion and > a recursion limit error. > > Rather than post my actual functions that are quite long, I've reduced > my problem to the code below that shows my issue. As you will see, > FindRoot keeps optvar in symbolic form when executing FindRoot. Is there > a way to force Mathematica to use all numerical calculations using > NMinimize or FindMinimum? Is the issue with calculation of the > gradient, which Mathematica wants to do symbolically? > > Many thanks. > > > > MyNumFct[optvar_] := Module[{inteq, n}, > inteq[x_] := (Sin[x] + 1/2*Cos[x])/optvar; > n = n /. FindRoot[inteq[n], {n, 0.1}]; > Return[n + Sin[optvar]]; > ] > > NMinimize[{MyNumFct[var], 0 <= var <= 6}, {var, 4.1}] >
- References:
- NMinimize problem: fct minimized uses FindRoot
- From: "Doug Tinkham" <dtinkham@live.ca>
- NMinimize problem: fct minimized uses FindRoot