1

I am trying to solve an equation that contains the minimzer of a function. A simple example is:

x[p_] := xx /. NMinimize[(xx - p)^2, xx][[2]]
NSolve[x[p] == 0, p]

During evaluation of In[1]:= NMinimize::nnum: The function value    (-0.829053-p)^2 is not a number at {xx} = {-0.829053}. >>

During evaluation of In[1]:= NMinimize::nnum: The function value (-0.829053-p)^2 is not a number at {xx} = {-0.829053}. >>

During evaluation of In[1]:= NMinimize::nnum: The function value (-0.829053-p)^2 is not a number at {xx} = {-0.829053}. >>

During evaluation of In[1]:= General::stop: Further output of NMinimize::nnum will be suppressed during this calculation. >>

During evaluation of In[1]:= ReplaceAll::reps: {xx} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. >>

During evaluation of In[1]:= ReplaceAll::reps: {xx} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. >>

Out[2]= {}

Does anyone know how to do this? (Of course the example is trivial, the actual functions I am using are much more complicated and require NMinimize and the same error arises there.)

This one works (thanks Michael!):

x[p_?NumericQ] := xx /. NMinimize[(xx - p)^2, xx][[2]]
FindRoot[x[p], {p, 0}]

Out[7]= {p -> 0.}
Konrad
  • 11
  • 2

0 Answers0