I am seeking a minimum of a function under an inequality constraint. How can I set stop condition? The problem is that $\nabla f_p$ never goes to zero. The function:

$$f(x_1, x_2)=\left(x_1 - 1\right)^2 + 2\left(x_2 - 2\right)^2$$

The constraint

$$g(x_1,x_2)=x_1^2 + x_2^2-1\leq 0$$

Objective function (with penalty method):

$$f_p(x_1,x_2)=\left(x_1 - 1\right)^2 + 2\left(x_2 - 2\right)^2+\mu\left(\max\left\{ x_1^2 + x_2^2-1, 0\right\}\right)^2$$

Its gradient (outside valid domain): $$\nabla f_p=\left(2\left(x_1 -1\right)+4\mu x_1^3\right)\widehat{x_1} + \left(4\left(x_2 - 2\right) + 4\mu x_2^3\right) \widehat{x_2}$$

Its gradient (inside valid domain): $$\nabla f_p=2\left(x_1 -1\right)\widehat{x_1} +4\left(x_2 - 2\right) \widehat{x_2}$$

It appears that $|\nabla f_p|$ oscillates around a value greater than one so testing $|\nabla f_p|$ does not work, or are the conditional derivatives wrong?


You calculated the gradient wrong (outside valid domain). Check your derivative of the penalty function. The partial derivative of


wrt $x_1$ is not

$$4 x_1^3.$$

Rather, it should be

$$4 x_1 (x_1^2+x_2^2-1)$$

(when outside the valid domain).

  • $\begingroup$ I realized that... $\endgroup$ – user877329 Jul 13 '16 at 5:53
  • $\begingroup$ @user877329, Thanks for reporting back. In that case (where you figured out the answer on your own), it would have been kind to have either answered your own question or deleted it, so no one wasted their time on explaining the answer. Just a tip for future reference. $\endgroup$ – D.W. Jul 13 '16 at 7:08
  • $\begingroup$ Or highlight common mistakes. $\endgroup$ – user877329 Jul 13 '16 at 7:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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