Lagrange multipliers are used to find the stationary points of a function of several variables subject to one or more constraints. Consider a $D$-demensional variable $\bold x$ with components $x_1,\ldots,x_D$. The constraint equation $g(\bold x)=0$ then represents a $(D-1)$-demensional surface in $\bold x$-space. Seek a point $\bold x^{*}$ on the constraint surface such that $f(\bold x)$ is maximized.
Consider a curve $\bold x(t)=(x_1(t),\cdots,x_D(t))$ going through the point $\bold x^{}$ with $\bold x(t_0)=\bold x^{}$ and lying on the constraint surface. Then we have
$$ \begin{aligned} \nabla g(\bold x(t))^{\text T}\bold x^{\prime}(t)&=\frac{\text d}{\text dt}\ g(\bold x(t))=0 \\ \nabla f(\bold x(t_0))^{\text T}\bold x^{\prime}(t_0)&=\frac{\text d}{\text dt}\ f(\bold x(t))\biggm|_{t=t_0}=0 \end{aligned} $$
with $\bold x^{\prime}(t)=(x_1^{\prime}(t),\cdots,x_D^{\prime}(t))$. We could obtain
$$ \nabla g(\bold x^{})^{\text T}\bold x^{\prime}(t_0)=0=\nabla f(\bold x^{})^{\text T}\bold x^{\prime}(t_0) $$
for any curve $\bold x(t)$ with the properties. This gives that $\nabla f$ and $\nabla g$ are parallel (or anti-parallel) at $\bold x^{*}$, and so there must exist a parameter $\lambda$ such that
$$ \nabla f+\lambda\nabla g=0 $$
where $\lambda\neq0$ is known as a Lagrange multiplier.
At this point, it is convenient to introduce the Lagrangian function defined by
$$ L(\bold x,\lambda)\equiv f(\bold x)+\lambda g(\bold x) $$
The constrained stationary condition is obtained by setting $\nabla_{\bold x}L=0$. Furthermore, the condition $\partial L/\partial\lambda=0$ leads to the constraint equation $g(\bold x)=0$.
Thus to find the maximum of a function $f(\bold x)$ subject to the constraint $g(\bold x)=0$, we define the Lagrangian function $L(\bold x,\lambda)$ and we then find the stationary point of $L(\bold x,\lambda)$ with respect to both $\bold x$ and $\lambda$.
We now consider the problem of maximizing $f(\bold x)$ subject to an inequality constraint of the form $g(\bold x)\geqslant0$. There are now two kinds of solutions possible,
according to whether the constrained stationary point lies in the region where $g(\bold x)>0$, in which
The constrained stationary point lies in the region where $g(\bold x)>0$. The function $g(\bold x)$ plays no role and so the stationary condition is simply $\nabla f(\bold x)=0$ . This corresponds to a stationary point of the Lagrange function with $\lambda=0$.
The constrained stationary point lies on the boundary $g(\bold x)=0$. It is analogous to the equality constraint discussed previously and corresponds to a stationary point of the Lagrange function with $\lambda\neq0$. For a solution point $\bold x^{}$ of this problem and a nearby point $\bold x+\bm \epsilon$ which is in the region $g(\bold x)>0$. Then we can consider a Taylor expansion around $\bold x^{}$, so that
$$ g(\bold x^{}+\bm\epsilon)-g(\bold x^{})\simeq \epsilon^{\text T}\nabla g(\bold x^{})\\ f(\bold x^{}+\bm\epsilon)-f(\bold x^{})\simeq \epsilon^{\text T}\nabla f(\bold x^{}) $$
Note that $g(\bold x^{}+\bm \epsilon)-g(\bold x^{})<0$ and $f(\bold x^{}+\bm \epsilon)-f(\bold x^{})>0$ . Thus we can conclude that $\nabla f$ and $\nabla g$ are anti-parallel, so that $\lambda>0$.
For either of these two cases, the product $\lambda g(\bold x)=0$. Thus the solution to the problem of maximizing $f(\bold x)$ subject to $g(\bold x)\geqslant0$ is obtained by optimizing the Lagrange function with respect to $\bold x$ and $\lambda$ subject to the conditions
$$ \begin{aligned} g(\bold x)&\geqslant0\\ \lambda&\geqslant0\\ \lambda g(\bold x)&=0 \end{aligned} $$
These are known as the Karush-Kuhn-Tucker(KKT) conditions.
Note that if we wish to minimize the function $f(\bold x)$ subject to an inequality constrain $g(\bold x)\geqslant0$, then we minimize the Lagrangian function $L(\bold x,\lambda)=f(\bold x)-\lambda g(\bold x)$ with respect to $\bold x$, subject to $\lambda\geqslant0$.