MathGroup Archive 2005

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

Search the Archive

Re: NMinimize ignores constraints and crashes

  • To: mathgroup at
  • Subject: [mg61305] Re: [mg61269] NMinimize ignores constraints and crashes
  • From: Andrzej Kozlowski <akoz at>
  • Date: Fri, 14 Oct 2005 22:22:35 -0400 (EDT)
  • References: <>
  • Sender: owner-wri-mathgroup at

On 14 Oct 2005, at 18:54, janusonis wrote:

> I saw somebody's similar message posted last year, but it went  
> unanswered,
> so I still need a solution.
> Why NMinimize ignores my constraints, gets into a region where my  
> function
> yields complex values, and then stops? I explicitly tell the  
> procedure not
> to go outside the constraints, but it still does it. A simple example:
> NMinimize[{Sqrt[x - y], x &#8805; y &&x y &#8805; 9}, {{x, 4., 5.},  
> {y,
> 3., 4.}}]
> NMinimize::nrnum: The function value 0.0819328+0.535013I is not a real
> number at {x, y} = {3.27193, 3.55817}.
> There are obviously infinitely many minima, at which the value of the
> function is 0. What is important here, though, is that NMinimize again
> ignores x>=y, gets complex values and chokes.

Next time you had better use InputForm when pasting Mathematica code.  
You can see what happened.

This question has been asked more than once in the past and has been  
answered. In fact I answered it myself at least once.
The constraints in NMinimize are not "absolute", instead "penalties"  
are used for violating them*. You can change the penalty function and  
make the penalties more severe but a better approach is to minimize  
the function Abs[Sqrt[x-y]] instead. Your problem should disappear.

Andrzej Kozlowski

*No use complaining - this is how the algorithm works.

Andrzej Kozlowski
Tokyo, Japan

  • Prev by Date: Re: Plotting a phase boundary
  • Next by Date: Re: Language vs. Library
  • Previous by thread: NMinimize ignores constraints and crashes
  • Next by thread: Plotting a phase boundary