# 拉格朗日乘数

${\displaystyle {\mathcal {L}}(x,y,\lambda )=f(x,y)-\lambda \cdot g(x,y)}$

${\displaystyle {\mathcal {L}}\left(x_{1},\ldots ,x_{n},\lambda _{1},\ldots ,\lambda _{k}\right)=f\left(x_{1},\ldots ,x_{n}\right)-\sum \limits _{i=1}^{k}{\lambda _{i}g_{i}\left(x_{1},\ldots ,x_{n}\right)},}$

## 介绍

${\displaystyle g\left(x,y\right)=c}$

c为常数。對不同${\displaystyle d_{n}}$ 的值，不难想像出

${\displaystyle f\left(x,y\right)=d_{n}}$

${\displaystyle \nabla f\left(x,y\right)=-\lambda \nabla \left(g\left(x,y\right)-c\right)}$

${\displaystyle \nabla {\Big [}f\left(x,y\right)+\lambda \left(g\left(x,y\right)-c\right){\Big ]}={\boldsymbol {0}}}$ .

${\displaystyle F\left(x,y,\lambda \right)}$  = ${\displaystyle f\left(x,y\right)+\lambda \left(g\left(x,y\right)-c\right)}$

## 证明

${\displaystyle f\left(x,y\right)=\kappa }$

${\displaystyle g\left(x,y\right)=c}$

${\displaystyle \mathrm {d} f={\frac {\partial {f}}{\partial {x}}}\mathrm {d} x+{\frac {\partial {f}}{\partial {y}}}\mathrm {d} y=0}$
${\displaystyle \mathrm {d} g={\frac {\partial {g}}{\partial {x}}}\mathrm {d} x+{\frac {\partial {g}}{\partial {y}}}\mathrm {d} y=0}$

${\displaystyle {\dfrac {\dfrac {\partial {f}}{\partial {x}}}{\dfrac {\partial {g}}{\partial {x}}}}={\dfrac {\dfrac {\partial {f}}{\partial {y}}}{\dfrac {\partial {g}}{\partial {y}}}}=-\lambda }$

${\displaystyle {\frac {\partial {f}}{\partial {x}}}+\lambda \cdot {\frac {\partial {g}}{\partial {x}}}=0}$
${\displaystyle {\frac {\partial {f}}{\partial {y}}}+\lambda \cdot {\frac {\partial {g}}{\partial {y}}}=0}$

${\displaystyle {\mathcal {L}}(x,y,\lambda )=f(x,y)+\lambda \cdot g(x,y)}$

## 拉格朗日乘数的运用方法

f定义为在Rn上的方程，约束为gk(x)= ck（或将约束左移得到gk(x) − ck = 0）。定义拉格朗日Λ

${\displaystyle \Lambda (\mathbf {x} ,{\boldsymbol {\lambda }})=f+\sum _{k}\lambda _{k}(g_{k}-c_{k})}$

${\displaystyle \nabla \Lambda =0\Leftrightarrow \nabla f=-\sum _{k}\lambda _{k}\nabla \ g_{k},}$

${\displaystyle \nabla _{\mathbf {\lambda } }\Lambda =0\Leftrightarrow g_{k}=c_{k}}$

${\displaystyle -{\frac {\partial \Lambda }{\partial {c_{k}}}}=\lambda _{k}}$

## 例子

• 很简单的例子

${\displaystyle f(x,y)=x^{2}y}$

${\displaystyle x^{2}+y^{2}=1}$

${\displaystyle g(x,y)=x^{2}+y^{2}-1}$
${\displaystyle \Phi (x,y,\lambda )=f(x,y)+\lambda g(x,y)=x^{2}y+\lambda (x^{2}+y^{2}-1)}$

${\displaystyle 2xy+2\lambda x=0}$
${\displaystyle x^{2}+2\lambda y=0}$
${\displaystyle x^{2}+y^{2}-1=0}$
• 另一个例子

${\displaystyle f(p_{1},p_{2},\ldots ,p_{n})=-\sum _{k=1}^{n}p_{k}\log _{2}p_{k}}$

${\displaystyle g(p_{1},p_{2},\ldots ,p_{n})=\sum _{k=1}^{n}p_{k}=1}$

${\displaystyle {\frac {\partial }{\partial p_{k}}}(f+\lambda (g-1))=0,}$

${\displaystyle {\frac {\partial }{\partial p_{k}}}\left(-\sum _{k=1}^{n}p_{k}\log _{2}p_{k}+\lambda (\sum _{k=1}^{n}p_{k}-1)\right)=0}$

${\displaystyle -\left({\frac {1}{\ln 2}}+\log _{2}p_{k}\right)+\lambda =0}$

${\displaystyle p_{k}={\frac {1}{n}}}$