描述
- 线性规划(一)——基本概念中“汽车工厂的生产、盈利”的数学模型较为简单,可以采用图解法。
- 但当目标函数、约束条件较为复杂时,将难以作图求解。
- 这个时候,我们可以采用“拉格朗日乘子法”。
拉格朗日乘子法的定义
- 定义
- 令 f ( x , y ) ∈ C ‘ f(x,y) \in C^` f(x,y)∈C‘(即一阶可导),且 ( x 0 , y 0 ) (x_0,y_0) (x0,y0)是满足 g ( x , y ) = 0 g(x,y)=0 g(x,y)=0时, f ( x , y ) f(x,y) f(x,y)的极值
- 限定 g ( x , y ) ∈ C ‘ g(x,y) \in C^` g(x,y)∈C‘,且 g ( x 0 , y 0 ) g(x_0,y_0) g(x0,y0)的梯度不等于 o ⃗ \vec{o} o
- 则存在 λ ∈ R \lambda \in \mathbb{R} λ∈R,使得
{ f ( x ) ‘ + λ g ( x ) ‘ = 0 f ( y ) ‘ + λ g ( y ) ‘ = 0 g ( x 0 , y 0 ) = 0 \begin{cases} f(x)^` + \lambda g(x)^`= 0 \\ f(y)^` + \lambda g(y)^` = 0 \\ g(x_0,y_0) = 0 \end{cases} ⎩ ⎨ ⎧f(x)‘+λg(x)‘=0f(y)‘+λg(y)‘=0g(x0,y0)=0
- 同样的,对于三元函数,乃至多元函数,都是成立的。关于三元函数的式子如下
{ f ( x ) ‘ + λ g ( x ) ‘ = 0 f ( y ) ‘ + λ g ( y ) ‘ = 0 f ( z ) ‘ + λ g ( z ) ‘ = 0 g ( x 0 , y 0 , z 0 ) = 0 \begin{cases} f(x)^` + \lambda g(x)^`= 0 \\ f(y)^` + \lambda g(y)^` = 0 \\ f(z)^` + \lambda g(z)^` = 0 \\ g(x_0,y_0, z_0) = 0 \end{cases} ⎩ ⎨ ⎧f(x)‘+λg(x)‘=0f(y)‘+λg(y)‘=0f(z)‘+λg(z)‘=0g(x0,y0,z0)=0
- 一般我们通过对于上面式子的分析、计算,就可以得到 f ( x , y ) f(x,y) f(x,y)的极值和极值点 ( x 0 , y 0 ) (x_0,y_0) (x0,y0)
题例
- 题目:求 f ( x , y ) = x 2 − y 2 − 2 y f(x,y)=x^2 - y^2 - 2y f(x,y)=x2−y2−2y在 x 2 + y 2 = 1 的条件下的极大值、极小值 x^2 + y^2 = 1的条件下的极大值、极小值 x2+y2=1的条件下的极大值、极小值
- 解
- 由题意,显然 g ( x , y ) = x 2 + y 2 − 1 g(x,y)=x^2+y^2-1 g(x,y)=x2+y2−1
- f ( x , y ) f(x,y) f(x,y)与 g ( x , y ) g(x,y) g(x,y)都存在一阶导数,分别计算其一阶导数可得
- f x ‘ = 2 x f_x^`=2x fx‘=2x, f y ‘ = − 2 y − 2 f_y^`=-2y-2 fy‘=−2y−2
- g x ‘ = 2 x g_x^`=2x gx‘=2x, g y ‘ = 2 y g_y^`=2y gy‘=2y
- 根据拉格朗日乘子法可得
{ 2 x + λ ∗ 2 x = 0 ( − 2 y − 2 ) + λ ∗ 2 y = 0 x 2 + y 2 − 1 = 0 \begin{cases} 2x + \lambda * 2x= 0 \\ (-2y - 2) + \lambda * 2y = 0 \\ x^2 + y^2 - 1 = 0 \end{cases} ⎩ ⎨ ⎧2x+λ∗2x=0(−2y−2)+λ∗2y=0x2+y2−1=0
- 整理后
{ x ( 1 + λ ) = 0 y ( λ − 1 ) − 1 = 0 x 2 + y 2 − 1 = 0 \begin{cases} x (1 + \lambda) = 0 \\ y(\lambda -1) -1 = 0 \\ x^2 + y^2 - 1 = 0 \end{cases} ⎩ ⎨ ⎧x(1+λ)=0y(λ−1)−1=0x2+y2−1=0
- 由于 x ( 1 + λ ) = 0 x (1 + \lambda) = 0 x(1+λ)=0,那么 x x x只能为 0 0 0或不为 0 0 0,现在开始讨论
- 当 x ≠ 0 x \ne 0 x=0时,计算上式可得: λ = − 1 \lambda = -1 λ=−1, y = − 1 2 y = -\frac{1}{2} y=−21, x = ± 3 2 x = \pm \frac{\sqrt{3}}{2} x=±23
- 当 x = 0 x = 0 x=0时,计算上式可得: y = ± 1 y = \pm 1 y=±1, x = 0 x=0 x=0
- 将 x x x、 y y y的值代入计算 g ( x 0 , y 0 ) g(x_0,y_0) g(x0,y0)的梯度 ( 2 x , 2 y ) (2x,2y) (2x,2y),结果都不等于 o ⃗ \vec{o} o 。因此上述 x x x、 y y y的值皆满足条件。
- 将 x x x、 y y y的值分别代入 f ( x , y ) f(x,y) f(x,y)可得
- f ( 3 2 , − 1 2 ) = 3 2 f(\frac{\sqrt{3}}{2},-\frac{1}{2})=\frac{3}{2} f(23 ,−21)=23
- f ( − 3 2 , − 1 2 ) = 3 2 f(-\frac{\sqrt{3}}{2},-\frac{1}{2})=\frac{3}{2} f(−23 ,−21)=23
- f ( 0 , 1 ) = − 3 f(0,1)=-3 f(0,1)=−3
- f ( 0 , − 1 ) = 1 f(0,-1)=1 f(0,−1)=1
- 显然
- 当 x = ± 3 2 , y = − 1 2 x = \pm \frac{\sqrt{3}}{2},y = -\frac{1}{2} x=±23 ,y=−21时, f ( x , y ) f(x,y) f(x,y)取得极大值 3 2 \frac{3}{2} 23
- 当 x = 0 , y = 1 x=0,y=1 x=0,y=1时, f ( x , y ) f(x,y) f(x,y)取得极小值 − 3 -3 −3
几何证明
- 证明:函数 f ( x , y ) f(x,y) f(x,y)在 g ( x , y ) = 0 g(x,y)=0 g(x,y)=0条件下的极值的必要条件
- 从几何上看,当 f ( x , y ) f(x,y) f(x,y)与 g ( x , y ) = 0 g(x,y)=0 g(x,y)=0在他们相切时能取到极值点 ( x 0 , y 0 ) (x_0,y_0) (x0,y0)
- 所以,在该极值点 ( x 0 , y 0 ) (x_0,y_0) (x0,y0)处, f ( x , y ) f(x,y) f(x,y)与 g ( x , y ) = 0 g(x,y)=0 g(x,y)=0的梯度比值相等,可得
f y ‘ ( x 0 , y 0 ) g y ‘ ( x 0 , y 0 ) = f x ‘ ( x 0 , y 0 ) g x ‘ ( x 0 , y 0 ) \frac{f_y^`(x_0,y_0)}{g_y^`(x_0,y_0)}=\frac{f_x^`(x_0,y_0)}{g_x^`(x_0,y_0)} gy‘(x0,y0)fy‘(x0,y0)=gx‘(x0,y0)fx‘(x0,y0)
- 我假设这个比例为 − λ -\lambda −λ,那么整理可得
f y ‘ ( x 0 , y 0 ) g y ‘ ( x 0 , y 0 ) = f x ‘ ( x 0 , y 0 ) g x ‘ ( x 0 , y 0 ) = − λ ⟹ { f x ‘ ( x 0 , y 0 ) + λ g x ‘ ( x 0 , y 0 ) = 0 f y ‘ ( x 0 , y 0 ) + λ g y ‘ ( x 0 , y 0 ) = 0 \frac{f_y^`(x_0,y_0)}{g_y^`(x_0,y_0)}=\frac{f_x^`(x_0,y_0)}{g_x^`(x_0,y_0)} =-\lambda \Longrightarrow \begin{cases} f_x^`(x_0,y_0) + \lambda g_x^`(x_0,y_0) = 0 \\ f_y^`(x_0,y_0) + \lambda g_y^`(x_0,y_0) = 0 \end{cases} gy‘(x0,y0)fy‘(x0,y0)=gx‘(x0,y0)fx‘(x0,y0)=−λ⟹{fx‘(x0,y0)+λgx‘(x0,y0)=0fy‘(x0,y0)+λgy‘(x0,y0)=0
- 再由条件 g ( x , y ) = 0 g(x,y)=0 g(x,y)=0,整理可得极值条件
{ f x ‘ ( x , y ) + λ g x ‘ ( x , y ) = 0 f y ‘ ( x , y ) + λ g y ‘ ( x , y ) = 0 g ( x , y ) = 0 \begin{cases} f_x^`(x,y) + \lambda g_x^`(x,y) = 0 \\ f_y^`(x,y) + \lambda g_y^`(x,y) = 0\\ g(x,y)=0 \end{cases} ⎩ ⎨ ⎧fx‘(x,y)+λgx‘(x,y)=0fy‘(x,y)+λgy‘(x,y)=0g(x,y)=0
L ( x , y , λ ) = f ( x , y ) + λ g ( x , y ) L(x,y,\lambda)=f(x,y)+\lambda g(x,y) L(x,y,λ)=f(x,y)+λg(x,y)
- 对其三个未知数 ( x , y , λ ) (x,y,\lambda) (x,y,λ)分别求导,并让导数等于0以求极值,可得到方程组如下
{ f x ‘ ( x , y ) + λ g x ‘ ( x , y ) = 0 f y ‘ ( x , y ) + λ g y ‘ ( x , y ) = 0 g ( x , y ) = 0 \begin{cases} f_x^`(x,y) + \lambda g_x^`(x,y) = 0 \\ f_y^`(x,y) + \lambda g_y^`(x,y) = 0\\ g(x,y)=0 \end{cases} ⎩ ⎨ ⎧fx‘(x,y)+λgx‘(x,y)=0fy‘(x,y)+λgy‘(x,y)=0g(x,y)=0
- 其结果与前面极值条件方程组一致
- 显然,我们可以知道求前面的条件极值等价于求 L ( x , y , λ ) = f ( x , y ) + λ g ( x , y ) L(x,y,\lambda)=f(x,y)+\lambda g(x,y) L(x,y,λ)=f(x,y)+λg(x,y)的极值
- 注:不是极值相等,而是说他们的极值点是同一个 ( x 0 , y 0 ) (x_0,y_0) (x0,y0)
- 这个方程即是“拉格朗日方程”, λ \lambda λ即是“拉格朗日乘子”