Re: How to use NMinimize with a numerical function
- To: mathgroup at smc.vnet.net
- Subject: [mg65393] Re: How to use NMinimize with a numerical function
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Thu, 30 Mar 2006 05:29:43 -0500 (EST)
- Organization: The Open University, Milton Keynes, UK
- References: <e0dpjp$qau$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Marco Gabiccini wrote: > Hi all, > > I wanted to test NMinimize[] with a numerical function whose return value > is the result of another NMinimize. > I defined the intersection with the abscissa of the parabola y=ax^2+bx+c as > f[a,b,c] > and I want to find one set of values {a,b,c} for which that intersection is > reached at x=-2. > > I defined > > f[a_, b_, c_] := > Module[{x}, NMinimize[{(a x^2 + b x + c)^2}, x][[2, 1, 2]]] > > and I would like to find that particular value of {a,b,c} for which > f[a,b,c]=-2, that is why I call > > FindMinimum[(f[r, s, t] + 2.0)^2, {{r, -5, 5}, {s, -5, 5}, {t, -5, 5}}] > > but I get this error message > 1760692.jpg > > [Attachments are not permitted. Please contact the author to > obtain this - moderator] > > It seems that the latter FindMinimum[] keeps the r,s,t unevaluated when > calling f in the first FindMinimum. Is there a way to switch the order of > evaluation? > > Can anybody help me? > > Marco > > Checking that the arguments of the function f are numerics should help. In[1]:= f[(a_)?NumericQ, (b_)?NumericQ, (c_)?NumericQ] := Module[{x}, NMinimize[{(a*x^2 + b*x + c)^2}, x][[2,1,2]]] Regards, JM