MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: How to use NMinimize with a numerical function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg65406] Re: [mg65362] How to use NMinimize with a numerical function
  • From: Darren Glosemeyer <darreng at wolfram.com>
  • Date: Thu, 30 Mar 2006 05:30:06 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

The behavior you have noticed is described in the following Technical 
Support FAQ.

http://support.wolfram.com/mathematica/mathematics/numerics/nsumerror.html

NumericQ constraints can be imposed on its arguments to keep f from 
evaluating before the arguments are numeric, and the FindMinimum call will 
evaluate as expected.


In[1]:= f[a_?NumericQ,b_?NumericQ,c_?NumericQ]:=
            Module[{x}, NMinimize[{(a x^2 + b x + c)^2}, x][[2, 1, 2]]]

In[2]:= FindMinimum[(f[r, s, t] + 2.0)^2, {{r, -5, 5}, {s, -5, 5}, {t, -5, 5}}]

NMinimize::cvmit: Failed to converge to the requested accuracy or precision 
within 100
      iterations.

                    -23
Out[2]= {2.08333 10   , {r -> -1.25, s -> -5., t -> -5.14745}}


Darren Glosemeyer
Wolfram Research


At 04:05 AM 3/28/2006 -0500, 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


  • Prev by Date: Re: solving
  • Next by Date: Re: Problem with Thread over Plus?
  • Previous by thread: Re: How to use NMinimize with a numerical function
  • Next by thread: Re: How to use NMinimize with a numerical function