I going to show you how to minimize this quadratic cost function:
$$ J = 5x^2 + 6y^2 - 2z^2 + 3x - 6y + z + 50$$
We want $J$ to be small as possible and it would be very easy to set $z = -50$ and $x = y = 0$. But then we say we have a limit in our cost function. Also called a constraint:
We say that $$z \leq 4$$ $$3x + y - z \leq 2$$ $$-6x + 2y +2z \leq 0$$
Those are our limits.
So what is the smallest possible value $J$ can have then?
We can write all that on the quadratic objective form with Lagrange Multipliers:
$$J = \frac{1}{2}u^TEu + u^TF + \lambda^T(Mu - \gamma)$$
Where
$$E = \begin{bmatrix} 5 &0 &0 \\ 0 & 6 & 0\\ 0 &0 & -2 \end{bmatrix}$$
$$u = \begin{bmatrix} x\\ y\\ z \end{bmatrix}$$
$$F = \begin{bmatrix} 3 \\ -6\\ 1 \end{bmatrix}$$
The factor of $50$ can be skipped, but we need to count with it when we found our minimized $J$.
$$M = \begin{bmatrix} 0 & 0 & 1\\ 3& 1 &-1 \\ -6 & 2 & 2 \end{bmatrix}$$
$$\gamma = \begin{bmatrix} 4\\ 2\\ 0 \end{bmatrix}$$
What we missing now is the vector $\lambda^T$ and I'm going to find that. In this case the vector $\lambda$ would have 3 numbers but non of those numbers can be negative. That means our minimizing is not optimal.
$$\lambda^T \geq 0$$
Let's say that I solve this and I got $\lambda = \begin{bmatrix} 2.545\\ -0.3\\ 4.234 \end{bmatrix}$
Does that mean that I can remove the constraint $3x + y - z \leq 2$ and try over again?
In that case, $M$ and $\gamma$ would be:
$$M = \begin{bmatrix} 0 & 0 & 1\\ -6 & 2 & 2 \end{bmatrix}$$
$$\gamma = \begin{bmatrix} 4\\ 0 \end{bmatrix}$$
And If I got a negative value on one of the elements in the vector $\lambda$, I need to remove the corresponding constraint and try until I got a vector $\lambda$ will all non-negative values?
To solve this simple problem with the help of the so called Lagrange multipliers you should avoid the inequality constraints using instead equality equivalences.
Calling
$$ f(x,y,z) = 5 x^2 + 6 y^2 - 2 z^2 + 3 x - 6 y + z + 50 $$ $$ \begin{array}{rcl} g_1(x,y,z,e) & = & z-4+e^2\\ g_2(x,y,z,e) & = & 3x+y-z-2+e^2\\ g_3(x,y,z,e) & = & -6x+2y+2z+e^2 \end{array} $$
The minimization problem then can be formulated as
$$ L = f(x,y,z) = \sum_{k=1}^4 \lambda_k g_k(x,y,z,e_k) $$
The stationary conditions are
$$ \nabla L = \left\{ \begin{array}{rcl} 3 + 3 \lambda_2 - 6 \lambda_3 + 10 x & = & 0\\ -6 + \lambda_2 + 2 \lambda-3 + 12 y & = & 0\\ 1 + \lambda_1 - \lambda_2 + 2 \lambda_3 - 4 z & = & 0\\ 2 e_1 \lambda_1 & = & 0\\ 2 e_2 \lambda_2 & = & 0\\ 2 e_3 \lambda_3 & = & 0\\ -4 + e_1^2 + z & = & 0\\ -2 + e_2^2 + 3 x + y - z & = & 0\\ e_3^2 - 6 x + 2 y + 2 z & = & 0 \end{array} \right. $$
After solving we get
$$ \begin{array}{cccccccccc} x & y & z & e_1 & e_2 & e_3 & \lambda_1 & \lambda_2&\lambda_3& f \\ 5/3 & 1& 4& 0& 0&0& 76/9& -113/18& 5/36& 368/9\\ 159/118 & 5/118& 4& 0& -\sqrt{(113/59)}& 0& 561/59 & 0& 162/59 &8231/236\\ 159/118&5/118&4& 0& \sqrt{113/59}& 0& 561/59& 0&162/59&8231/236\\ 9/13&1& 14/13& -\sqrt{(38/13)}& 0& 0& 0&- 121/26& -35/52&692/13\\ 9/13& 1&14/13& \sqrt{38/13}&0& 0&0&-121/26&-35/52&692/13\\ 69/88&141/176&203/176&-\sqrt{501/11}/4& 0&-\sqrt{35/11}/2&0&-159/44&0&18643/352\\ 69/88&141/176&203/176&\sqrt{501/11}/4&0&\sqrt{35/11}/2&0&-159/44&0&18643/352\\ 69/88&141/176&203/176&\sqrt{501/11}/4&0&\sqrt{35/11}/2& 0&-159/44&0&18643/352\\ 3/8&5/16&13/16&-\sqrt{51}/4&-\sqrt{(11/2)}/2& 0&0&0& 9/8&1601/32\\ 3/8& 5/16& 13/16&-\sqrt{51}/4&\sqrt{11/2}/2& 0&0&0& 9/8&1601/32\\ 3/8&5/16&13/16&\sqrt{51}/4& -\sqrt{(11/2)}/2& 0& 0&0&9/8&1601/32\\ \end{array} $$
Giving the corresponding values for $f(x,y,z)$