Re: Problem with NMaximize
- To: mathgroup at smc.vnet.net
- Subject: [mg68842] Re: Problem with NMaximize
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Mon, 21 Aug 2006 03:27:39 -0400 (EDT)
- Organization: The Open University, Milton Keynes, UK
- References: <ec97qm$4dt$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Lee Newman wrote:
> I have function that I want to maximize. The function calls many other
> functions, and I have verified that on its own, it works as intended.
> However, when I include the function in an NMaximize statement, I get
> errors. After including Print statements within the function (and the
> functions that calls), it seems the problem is that the variable being
> passed to the function by NMaximize is being treated as a undefined
> symbol, rather than as the value currently being passed by NMaximize.
>
> NMaximize[ {bigFunc[a,b,c]}, {{a,0,1},{b,0,2},{c,0,3}},
> Method->"NelderMead"];
>
> bigfunc[x_,y_,z_] := Module[{vars here}, large function here; Print[y]];
>
> When called directly bigfunc[1,2,3], the print statement prints 2, the
> correct value for argument y.
> When called within NMaximize (as above), the print statement returns b,
> the symbolic value passed by NMaximize, and all the errors generated are
> related to the fact that b is being treated as a undefined symbol rather
> than a numeric value.
Hi Lee,
Define your function so it will be called only if numerics arguments are
supplied:
bigfunc[x_?NumericQ, y_?NumericQ, z_?NumericQ] := Module[{vars here},
large function here; Print[y]];
HTH,
Jean-Marc