Consider the following NLP problem. I have solved it using KTP condition. In case II, I get $\lambda = -\sqrt{\frac{2}{3}}$ , but we know that according to the KTP condition $\lambda$ must be $\geq 0$. So I am confused about whether I computed the problem accurately or not.
Question:
Maximize $f(x,y) = xy$
Subject to, $x + y^2 \leq 2$ and $x,y \geq 0$
Solution:
We have,
$f(x,y) = xy$
$g(x,y) = x + y^2 - 2$
Now, $L(x,y) = xy + \lambda(x + y^2 - 2)$
The Kuhn-Tucker conditions are:
$\frac{\partial L}{\partial x} = 0$
$\frac{\partial L}{\partial y} = 0$
$\lambda g(x,y) = 0$
$g(x,y) \leq 0$
$\lambda \geq 0$
Applying these conditions, we get
$y + \lambda = 0$ ......... (i)
$x + 2\lambda y = 0$ ......... (ii)
$\lambda (x + y^2 - 2) = 0$ ......... (iii)
$x + y^2 - 2 \leq 0$ ......... (iv)
$\lambda \geq 0$ ......... (v)
From (iii), either $\lambda = 0$ or $x + y^2 - 2 = 0$
- Case I:
When $\lambda = 0$ , from (i) and (ii) we get $x = 0$ and $y = 0$
- Case II
When $x + y^2 - 2 = 0$ , solving (i) and (ii), we get $x = \frac{4}{3}$ , $y = \sqrt{\frac{2}{3}}$ and $\lambda = -\sqrt{\frac{2}{3}}$
$f(0,0) = 0$
$f(\frac{4}{3} , \sqrt{\frac{2}{3}}) = \frac{4\sqrt{2}}{3\sqrt{3}}$
Therefore, the optimal solution is $x = \frac{4}{3}$ , $y = \sqrt{\frac{2}{3}}$ , which gives $f$max $= \frac{4\sqrt{2}}{3\sqrt{3}}$.
Am I computed the NLP problem correctly?
It looks like you are lucky and indeed obtaining the correct solution, but your derivation contains mistakes.
First, as I stated in the comment, you forgot to encode the conditions $x \geq 0$ and $y \geq 0$. These conditions are important because the objective function $xy$ can be very large while satisfying $x+y^2 \leq 2$ . For example, take $y=-n$ and $x=-n^2$. Then $x+y^2=-n^2+n^2 = 0 \leq 2$ and $xy = n^3 \gg 1$. So the objective function is unbounded when you remove the constraints $x,y \geq 0$. They are important! The fact that you obtain the correct answer without encoding them is due to the absence of local extremizer in the other region.
Second, as you noted, you have a problem with the sign of your multiplier. This is because you are considering a maximization problem, so you should set: $$ L(x,y) := - f(x,y) + \lambda g(x,y) $$ if your objective is to maximize $f$ under the constraint $g \leq 0$. See the Karush-Kuhn-Tucker page on Wikipedia. All your computations remain the same, except with the opposite sign on $\lambda$, which is what you were looking for.
Even though you obtain the correct value of $f_{\max}$, please try to encode the conditions $x, y \geq 0$, at least as an instructional exercise.