Services & Resources / Wolfram Forums / MathGroup Archive

MathGroup Archive 2010

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

Search the Archive

Re: problems with NMinimize

  • To: mathgroup at
  • Subject: [mg109434] Re: problems with NMinimize
  • From: "Ingolf Dahl" <ingolf.dahl at>
  • Date: Tue, 27 Apr 2010 04:05:38 -0400 (EDT)

Try with


f[myVec_?(VectorQ[#,NumericQ]&), myParam_, myModel_] := < function


instead of your condition test at the end. The parenthesis around
VectorQ[#,NumericQ]& is essential. I have tested with 


func[v_?(VectorQ[#, NumericQ] &)] := Mean[v]


and that seems to work.

 Still I would like to be able to say to NMininize directly: "I understand
that you do symbolic evaluation of f behind my back with the very best
intentions, but this time I prefer to say NO to this - you should not even


Best regards


Ingolf Dahl


From: Joe Hays [mailto:hays.joe at] 
Sent: den 26 april 2010 15:34
To: Ingolf Dahl
Cc: mathgroup at
Subject: [mg109434] Re: [mg109420] Re: problems with NMinimize


So, on this topic I'd like to ask the group for some pointers...


First Observation:

I generally have a vector function that I need to pass to NMinimize and/or
FindMinimum. I have not had success with either of the following


 f(myVec_?NumericQ):= Module[{}, <body of function definition>]




f(myVec_?VectorQ):= Module[{}, <body of function definition>]


the only thing I have found to work is,


f(myVec_):= Module[{}, <body of function


This was very difficult to find, and as I recall, I didn't find it in the
documentation but in a forum posting. I hope the Wolfram folks consider
adding an example when dealing with a vector valued function in their


Now, a question:

Not only do I have a vector valued function to be minimized but I also have
additional arguments that I need to pass to the function for proper
evaluation. So, if I make the following definition,


f(myVec_, myParam_, myModel_):= Module[{}, <body of function


where myParam is just a constant and myModel is a sybolic set of equations.
If I then pass this function definition to NMinimize/FindMinimum by,


myParam = <some Real constant>;

myModel = <some symbolic equation>;

NMinimize[ f[myVec, myParam, myModel],  myVec ]


will Mathematica try to symbolically evaluate myModel? 


Sorry, this is likely a Rookie question but I've had really poor performance
with both NMinimize and FindMinimum with multiple problems I've tried with
it. I'm trying to find reasons as to why this performance is so poor. It's
likely due to my poor Mathematica code (in the body), or my formulation,
however, I have been curious about this specific question for some time now.
So, if anyone has more insight to this mechanism of bypassing symbolic
evaluations (or not) your comments.




On Mon, Apr 26, 2010 at 7:32 AM, Ingolf Dahl <
<mailto:ingolf.dahl at> ingolf.dahl at> wrote:

Best LAI,
Yes, if you followed the thread back, you see that we also have understood
that we might introduce an extra function f(a_?NumericQ,b_?NumericQ, ...),
but we (I guess I can include Alexey Popkov and Joe Hays in "we") sometimes
find that way clumsy. If we ask Mathematica to evaluate NMinimize, this
function is described to "minimizes f numerically with respect to x." But it
does not only this: it also first tries to evaluate f symbolically. I find
it reasonable that there should be a way to opt-out from this symbolic
evaluation. It would be convenient to have an option to NMinimize for this

Ingolf Dahl

-----Original Message-----

From: Anh Ngoc LAI [mailto: <mailto:laianhngoc at>
laianhngoc at]
Sent: den 26 april 2010 10:50
To:  <mailto:mathgroup at> mathgroup at

Subject: [mg109434] [mg109420] [mg109413] Re: problems with NMinimize


One way to solve this problem (if i understand your problem) is to define
your function so that only evaluates when its argument is numeric, as

f(a_?NumericQ,b_?NumericQ, ...) == ...


--- On Sun, 4/25/10, Alexey Popkov < <mailto:lehin.p at>
lehin.p at> wrote:

From: Alexey Popkov < <mailto:lehin.p at> lehin.p at>

Subject: [mg109434] [mg109420] [mg109413] [mg109405] Re: problems with NMinimize

To:  <mailto:mathgroup at> mathgroup at
Date: Sunday, April 25, 2010, 6:25 AM

"Ingolf Dahl" < <mailto:ingolf.dahl at>
ingolf.dahl at> 

> Is there any serious Mathematica user in this forum, which has not
> stumbled
> on this problem one or several times, when NMinimize, or some other
> function, tries to evaluate a numeric function symbolically first, before
> inserting the numbers? Sometimes it would be nice to have an option,
> SymbolicEvaluation->False, which could be set for NMinimize in these
> cases.
> It is not always so convenient to have to define an extra function just to
> take care of this. I think there is a whole group of commands acting
> similarly to NMinimize.
> Ingolf Dahl
> Sweden

I totally agree with you. I do not see anything reasonable in that obviously
numerical function (for example, NMinimize, FindMinimum, etc.) is trying for
some reason to perform symbolic computation.

  • Prev by Date: Re: problems with NMinimize
  • Next by Date: Why Return[] does not work?
  • Previous by thread: Re: problems with NMinimize
  • Next by thread: Re: problems with NMinimize