Minimize difference with constraint that the variable is nonnegative

75 Views Asked by At

$$ \text{minimize} \quad (x-y)^2 \quad \text{subject to } y \ge0 $$

I know the answer is quite simple:

  • when $x \geq 0$, $y=x$.
  • when $x < 0$, $y=0$.

Any idea how I could formally get this? I tried the Lagrangian with slack variables.

$$L(y,\alpha,t)=(x-y)^2+\alpha(y-t^2)$$

This gives the three equations:

$$ \alpha t=0, \qquad y-x+\frac{1}{2}\alpha = 0, \qquad y=t^2 $$

Here for the $2$ cases, $\alpha = 0$ and $t=0$, we get $y=x$ and $y=0$. However, from this, how do I get the respective conditions on $x$?

1

There are 1 best solutions below

0
On

The $\alpha=0$ case yields $y=x=t^2$, so $x \ge 0$. If $x<0$, then $x=y+\alpha/2$ and $y \ge 0$ together imply that $\alpha<0$, so $t=0$, which yields $y=0$.