I am confused about the solution to this constrained optimization problem.
$$\text{Minimize } x^2 \text{ such that } x\leq3$$
$$x\leq3 \iff x-3\leq0$$
Hence we want $x-3$ to be small.
Therefore, we need to minimize $$p=x^2 + \lambda(x-3)$$
$$\dfrac{\partial p}{\partial x} = 2x + \lambda $$
$$\dfrac{\partial p}{\partial x} =0 \iff x=\dfrac{-\lambda}{2}$$
Define $$d = \left (\dfrac{-\lambda}{2}\right )^2 + \lambda\left(\dfrac{-\lambda}{2}-3\right) = -3\lambda -\dfrac{\lambda^2}{4}$$
$$\dfrac{\partial d}{\partial \lambda}=-3-\dfrac{\lambda}{2}$$
$$\dfrac{\partial d}{\partial \lambda}=0 \iff \lambda=-6$$
$$\lambda=-6 \implies x=-3$$
The correct solution however is $x=0$. What am I missing? Using the same method and reversing the constraint to $x\geq3$ gives the correct answer for that case. Is it that we needed $\lambda \geq0$? In such a case must that also be reflected by a Lagrange term in the primal?
One mistake is in the very beginning: "$x\leq3 \iff 3-x\color{red}{\leq}0$" is not true; instead, it must be "$x\leq3 \iff 3-x\geq0$".