6
$\begingroup$

Mathematica 10 generates a warning that it is unable to generate initial points for numerical optimization problems. I picked a particularly simple example. The problem goes away when Abs is dropped.

NMinimize[{x + y, x >= 0 && Abs[x + 10 y + 100] <= 1}, {x, y}]

NMinimize::incst: "NMinimize was unable to generate any initial points satisfying the inequality constraints {-1+Abs[100+x+10\ y]<=0}. The initial region specified may not contain any feasible points. Changing the initial region or specifying explicit initial points may provide a better solution."

Despite the warning, Mathematica computes the correct solution. How can I get rid of the warning?

$\endgroup$
3
  • $\begingroup$ You can use Off. $\endgroup$ Commented Nov 13, 2014 at 16:21
  • $\begingroup$ True but I prefer to understand why Mathematica generates the warning and what it needs not to generate it. $\endgroup$
    – Mathxy
    Commented Nov 13, 2014 at 16:29
  • 1
    $\begingroup$ One way that works is to replace Abs[expr]<=val with expr<=val&&-expr<=val. I do not know whether this will work in general but I expect it to be useful when expr is linear (NMinimize uses some linear programming to get initial points). $\endgroup$ Commented Nov 13, 2014 at 17:23

2 Answers 2

7
$\begingroup$

You can get a glimpse into the workings of NMinimize by turning on the debug-printing:

Block[{Optimization`NMinimizeDump`dbPrint = Print},
 NMinimize[{x + y, x >= 0 && Abs[x + 10 y + 100] <= 1}, {x, y}]
 ]

It seems at a cursory glance that it decided to search for points in the rectangle:

{{x,0.,2.},{y,-1,1}}

In this region it found zero of the three points it needs for the default Nelder-Mead method.

However, sometimes simplifying the constraints helps:

NMinimize[{x + y, 
  Reduce[x >= 0 && Abs[x + 10 y + 100] <= 1, {x, y}, Reals]}, {x, y}]

(*  {-10.1, {x -> 0., y -> -10.1}}  *)

No messages.

$\endgroup$
10
$\begingroup$

Documentation states: "This error can typically be avoided by providing starting values for the variable".

Lets try to find these values:

 FindInstance[{x >= 0, Abs[100 + x + 10 y] <= 2}, {x, y}, Reals]

{{x -> 0, y -> -(49/5)}}

FindInstance[{x >= 1, Abs[100 + x + 10 y] <= 1}, {x, y}, Reals]

{{x -> 1, y -> -10}}

Lets try:

 NMinimize[{x + y, 
      x >= 0 && Abs[x + 10 y + 100] <= 1}, {{x, 0, 1}, {y, -10, -49/5}}]

{-10.1, {x -> 0., y -> -10.1}}

And no error report.

$\endgroup$
4
  • $\begingroup$ In the answer, you use two points satisfying the constraints rather than one. Is it necessary to do so? In case it isn't, would the proper syntax be {{x,0},{y,-10}}? I couldn't find this info in the online documentation for NMinimize. $\endgroup$
    – Patricio
    Commented Mar 13, 2019 at 11:48
  • $\begingroup$ @Patricio Mathematica has a lot of undocumented features and commands. Your simply should try. Note, however, that by specifying one and two point condition your automatically use different Minimization methods. $\endgroup$
    – Acus
    Commented Mar 13, 2019 at 11:56
  • $\begingroup$ I was trying as you answered. I get the message Maximize::ivar: {x,0.23} is not a valid variable. Any suggestions? $\endgroup$
    – Patricio
    Commented Mar 13, 2019 at 11:59
  • $\begingroup$ Ok. I see. I typed Maximizeinstead of NMaximize. When I use NMaximize it asks for a lower and and upper bound. Thanks. $\endgroup$
    – Patricio
    Commented Mar 13, 2019 at 12:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.