到目前为止,这个系列主要集中在只有一个自变量的函数上。大多数量都依赖于多个变量。一个圆柱形罐子的体积取决于它的半径 r r r 和它的高度 h : h\mathclose{\text{:}} h : V = π r 2 h 。 V = \pi r^2 h\mathclose{\text{。}} V = π r 2 h 。 天气图上的温度取决于两个坐标,房间内的温度取决于三个坐标,机器学习模型的误差则取决于其所有的参数,通常有数百万个参数。本模块将导数扩展到这样的函数。两个变量已经展示了主要的新思想,而接下来的大部分内容,无论是三个变量还是数百万个变量,都不会改变。
定义 17.1二元函数
一个 二元函数 f f f 是一个规则,它将集合 D D D 中的每一个有序实数对 ( x , y ) (x, y) ( x , y ) 恰好对应一个实数 f ( x , y ) , f(x, y)\mathclose{\text{,}} f ( x , y ) , 读作 “f of x, y”。集合 D , D\mathclose{\text{,}} D , 即平面上的点集,是 f f f 的定义域 ,而所有 ( x , y ) (x, y) ( x , y ) 在 D D D 中的取值所组成的集合 f ( x , y ) f(x, y) f ( x , y ) 是它的 值域 。一个 三元函数 将空间中集合 D D D 的每一个点 ( x , y , z ) (x, y, z) ( x , y , z ) 对应一个数 f ( x , y , z ) 。 f(x, y, z)\mathclose{\text{。}} f ( x , y , z ) 。
如模块 1 所述,当一个函数由公式给出且未说明其定义域时,定义域是使公式给出实数的所有点的集合。通常写作 z = f ( x , y ) , z = f(x, y)\mathclose{\text{,}} z = f ( x , y ) , 并称 x x x 和 y y y 为 自变量 ,称 z z z 为 因变量 。
例 17.1定义域与值域 ✓ 已检验
求 (a) f ( x , y ) = 9 − x 2 − y 2 f(x, y) = \sqrt{9 - x^2 - y^2} f ( x , y ) = 9 − x 2 − y 2 和 (b) g ( x , y ) = ln ( y − x 2 ) g(x, y) = \ln(y - x^2) g ( x , y ) = ln ( y − x 2 ) 的定义域和值域。
(a) 需要 9 − x 2 − y 2 ≥ 0 , 9 - x^2 - y^2 \ge 0\mathclose{\text{,}} 9 − x 2 − y 2 ≥ 0 , 即 x 2 + y 2 ≤ 9 。 x^2 + y^2 \le 9\mathclose{\text{。}} x 2 + y 2 ≤ 9 。 由于 x 2 + y 2 x^2 + y^2 x 2 + y 2 是 ( x , y ) (x, y) ( x , y ) 到原点的距离的平方(模块 16),定义域是以原点为中心、半径为 3 的圆盘,包括其边界,即圆 x 2 + y 2 = 9 。 x^2 + y^2 = 9\mathclose{\text{。}} x 2 + y 2 = 9 。 在该定义域上,9 − x 2 − y 2 9 - x^2 - y^2 9 − x 2 − y 2 介于 0 与 9 之间,因此 f ( x , y ) f(x, y) f ( x , y ) 介于 0 与 3 之间。[ 0 , 3 ] [0, 3] [ 0 , 3 ] 中的每个数都是值:沿 x x x 轴,当 x x x 从 3 降到 0 时,f ( x , 0 ) = 9 − x 2 f(x, 0) = \sqrt{9 - x^2} f ( x , 0 ) = 9 − x 2 覆盖 [ 0 , 3 ] [0, 3] [ 0 , 3 ] 的所有值。值域是 [ 0 , 3 ] 。 [0, 3]\mathclose{\text{。}} [ 0 , 3 ] 。
(b) 对数需要 y − x 2 > 0 , y - x^2 > 0\mathclose{\text{,}} y − x 2 > 0 , 即 y > x 2 : y > x^2\mathclose{\text{:}} y > x 2 : 定义域是抛物线 y = x 2 y = x^2 y = x 2 上方的区域,不包括抛物线本身。沿 y y y 轴,当 y y y 遍历 ( 0 , ∞ ) (0, \infty) ( 0 , ∞ ) 时,g ( 0 , y ) = ln y g(0, y) = \ln y g ( 0 , y ) = ln y 取遍所有实数值,因此值域是 R 。 \R\mathclose{\text{。}} R 。
图像
函数f f f 的图 是空间中满足z = f ( x , y ) z = f(x, y) z = f ( x , y ) 和( x , y ) (x, y) ( x , y ) 在定义域内的点( x , y , z ) (x, y, z) ( x , y , z ) 的集合。在定义域的每个点( x , y ) (x, y) ( x , y ) 上方,它恰好有一个点,高度为f ( x , y ) 。 f(x, y)\mathclose{\text{。}} f ( x , y ) 。 对于平面区域上的连续函数,可将图视为一个曲面 (图17.1,左侧)。例17.1中f ( x , y ) = 9 − x 2 − y 2 f(x, y) = \sqrt{9 - x^2 - y^2} f ( x , y ) = 9 − x 2 − y 2 的图是一个穹顶:对z = 9 − x 2 − y 2 z = \sqrt{9 - x^2 - y^2} z = 9 − x 2 − y 2 平方得到x 2 + y 2 + z 2 = 9 , x^2 + y^2 + z^2 = 9\mathclose{\text{,}} x 2 + y 2 + z 2 = 9 , 其中z ≥ 0 z \ge 0 z ≥ 0 是中心在原点、半径为3的球体的上半部分。线性函数f ( x , y ) = a x + b y + c f(x, y) = ax + by + c f ( x , y ) = a x + b y + c 的图是一个平面(模块16)。
用手绘制曲面很困难,即使计算机绘制的图像也会将某些部分隐藏在另一些部分之后。制图师早已解决了这个问题。
等高线与等值线图
徒步地图并不以三维方式显示山地。它绘制 等高线 ,这些线连接的是同一海拔高度上的点,并标注相应的高度。天气图也采用相同的方式绘制 等温线 ,即温度相等的曲线,以及 等压线 ,即气压相等的曲线。
定义 17.2等高线
对二元函数 f , f\mathclose{\text{,}} f , 每取其值域中的一个常数 k , k\mathclose{\text{,}} k , 所有满足 f ( x , y ) = k f(x, y) = k f ( x , y ) = k 的点就组成 f f f 的一个等值集 。等值集通常是曲线,称为等值线 ,也可以是一个点或整个区域。按等间隔选取常数 k , k\mathclose{\text{,}} k , 画出各等值线并标注对应的数值,就得到 f f f 的等值线图 。
等高线 f ( x , y ) = k f(x, y) = k f ( x , y ) = k 是定义域内使曲面高度为 k k k 的点的集合:用水平平面 z = k z = k z = k 剖开曲面,并从上方观察剖面。图 17.1 展示了一个有两个峰的曲面,其等高线在相应高度上绘制在曲面上,并形成了等高线图。
图 17.1 左:函数 f ( x , y ) = ( x 2 + 3 y 2 ) e 1 − x 2 − y 2 f(x, y) = (x^2 + 3y^2)e^{1 - x^2 - y^2} f ( x , y ) = ( x 2 + 3 y 2 ) e 1 − x 2 − y 2 的图像,是一个有两个高度为 ( 0 , ± 1 ) (0, \pm1) ( 0 , ± 1 ) 的峰的地形,原点处有一个凹陷,两个山口位于 ( ± 1 , 0 ) (\pm1, 0) ( ± 1 , 0 ) 处。其等高线 f = 0.5 , 1 , 1.5 , 2 , 2.5 f = 0.5, 1, 1.5, 2, 2.5 f = 0.5 , 1 , 1.5 , 2 , 2.5 在曲面上相应高度处绘制。右:从上方观察的相同等高线,即等高线图。等高线 f = 1 f = 1 f = 1 在山口处交叉。
等高线图的读法如下:
等高线密集的地方,曲面陡峭;等高线稀疏的地方,曲面平缓。在陡峭的坡度上,高度相等的步长所对应的水平距离较小。
小的闭合等高线围绕一点,表示峰或凹陷;标签会告诉你具体是哪一个。
在图 17.1 中的山口处,等高线 f = 1 f = 1 f = 1 交叉自身。
例 17.2一个穹顶的等高线 ✓ 已检验
描述k = 0 , 1 , 2 , 3 k = 0, 1, 2, 3 k = 0 , 1 , 2 , 3 的f ( x , y ) = 9 − x 2 − y 2 f(x, y) = \sqrt{9 - x^2 - y^2} f ( x , y ) = 9 − x 2 − y 2 的水平集f ( x , y ) = k , f(x, y) = k\mathclose{\text{,}} f ( x , y ) = k , 并解释它们如何显示圆顶的形状。
对于 0 ≤ k ≤ 3 , 0 \le k \le 3\mathclose{\text{,}} 0 ≤ k ≤ 3 , 9 − x 2 − y 2 = k \sqrt{9 - x^2 - y^2} = k 9 − x 2 − y 2 = k 表示 9 − x 2 − y 2 = k 2 9 - x^2 - y^2 = k^2 9 − x 2 − y 2 = k 2 (两边均为非负数,因此平方不会丢失信息),即,
x 2 + y 2 = 9 − k 2 , x^2 + y^2 = 9 - k^2, x 2 + y 2 = 9 − k 2 ,
以原点为中心,半径为 9 − k 2 \sqrt{9 - k^2} 9 − k 2 的圆。半径分别为 3, 8 ≈ 2.83 , \sqrt8 \approx 2.83\mathclose{\text{,}} 8 ≈ 2.83 , 5 ≈ 2.24 \sqrt5 \approx 2.24 5 ≈ 2.24 和 0:对于 k = 3 , k = 3\mathclose{\text{,}} k = 3 , “圆”是穹顶顶部的单点 ( 0 , 0 ) 。 (0, 0)\mathclose{\text{。}} ( 0 , 0 ) 。 相邻圆之间的间隔约为 0.17,0.59 和 2.24。这些圆在穹顶边缘附近密集(那里穹顶陡峭,其侧面是垂直的),而在顶部附近扩散(那里穹顶几乎平坦)。
注意
无标签的等高线图无法区分峰顶和凹陷:两者都可以有嵌套的闭合曲线。请阅读标签。不要将等值线与图形混淆: f ( x , y ) = x 2 + y 2 f(x, y) = x^2 + y^2 f ( x , y ) = x 2 + y 2 的正等值线是圆,而其在 0 处的等值集是一个点。其图形是一个碗形曲面 z = x 2 + y 2 , z = x^2 + y^2\mathclose{\text{,}} z = x 2 + y 2 , 在正高度处的水平截面即为这些圆。
三个变量和等值面
三元函数的图像需要四维空间。因此,人们研究其水平面 f ( x , y , z ) = k 。 f(x, y, z) = k\mathclose{\text{。}} f ( x , y , z ) = k 。 对于房间内的温度,它们是等温面。对于f ( x , y , z ) = x 2 + y 2 + z 2 , f(x, y, z) = x^2 + y^2 + z^2\mathclose{\text{,}} f ( x , y , z ) = x 2 + y 2 + z 2 , 即原点的距离平方,水平面f = k f = k f = k 是当k > 0 k > 0 k > 0 时以原点为中心、半径为k \sqrt k k 的球面,当k = 0 k = 0 k = 0 时是单点( 0 , 0 , 0 ) , (0, 0, 0)\mathclose{\text{,}} ( 0 , 0 , 0 ) , 当k < 0 k < 0 k < 0 时为空集。第17.6节求水平面的切平面。
在数轴上, x x x 只能从两个方向趋近于 a 。 a\mathclose{\text{。}} a 。 在平面上, ( x , y ) (x, y) ( x , y ) 可以从任何方向趋近于 ( a , b ) , (a, b)\mathclose{\text{,}} ( a , b ) , 沿直线、螺旋线或其他任何路径,且极限不应依赖于路径。
定义 17.3极限
设 f f f 在以 ( a , b ) (a, b) ( a , b ) 为中心的圆盘上每一点都有定义,除了可能在 ( a , b ) (a, b) ( a , b ) 本身。那么
lim ( x , y ) → ( a , b ) f ( x , y ) = L , \lim_{(x, y)\to(a, b)} f(x, y) = L, ( x , y ) → ( a , b ) lim f ( x , y ) = L ,
读作“f(x, y) 的极限,当 (x, y) 趋近于 (a, b) 时为 L”,如果对于每一个数 ε > 0 , \varepsilon > 0\mathclose{\text{,}} ε > 0 , 存在一个数 δ > 0 , \delta > 0\mathclose{\text{,}} δ > 0 , 使得 ∣ f ( x , y ) − L ∣ < ε \abs{f(x, y) - L} < \varepsilon ∣ f ( x , y ) − L ∣ < ε 对于每一个点 ( x , y ) (x, y) ( x , y ) 满足
0 < ( x − a ) 2 + ( y − b ) 2 < δ . 0 < \sqrt{(x - a)^2 + (y - b)^2} < \delta. 0 < ( x − a ) 2 + ( y − b ) 2 < δ .
这就是第 2.7 节 的 ε–δ 定义,只是把数轴上的距离 ∣ x − a ∣ \abs{x - a} ∣ x − a ∣ 换成了平面距离。无论从哪个方向接近,只要各点足够靠近 ( a , b ) , (a, b)\mathclose{\text{,}} ( a , b ) , 函数值 f ( x , y ) f(x, y) f ( x , y ) 就能任意接近 L 。 L\mathclose{\text{。}} L 。 这里以 ( a , b ) (a, b) ( a , b ) 为圆心的圆盘指到它的距离小于某个半径 ρ > 0 \rho > 0 ρ > 0 的点集。如果 ( a , b ) (a, b) ( a , b ) 在定义域边界上,例如例 17.1 的穹顶上的 ( 3 , 0 ) , (3, 0)\mathclose{\text{,}} ( 3 , 0 ) , 则定义不变,只把 ( x , y ) (x, y) ( x , y ) 限制在定义域内,就像单侧极限把 x x x 限制在一侧。
模块 2 中的极限法则同样成立,证明相同:和、积、商的极限分别是和、积、商的极限(对于商,当分母的极限不为 0 时)。特别地,对于 x x x 和 y y y 的多项式,或分母在 ( a , b ) (a, b) ( a , b ) 处不为 0 的有理函数,极限等于该值。例如, lim ( x , y ) → ( 1 , 2 ) x 2 y + 1 x + y = 2 + 1 3 = 1 。 \lim_{(x,y)\to(1,2)} \dfrac{x^2 y + 1}{x + y} = \dfrac{2 + 1}{3} = 1\mathclose{\text{。}} lim ( x , y ) → ( 1 , 2 ) x + y x 2 y + 1 = 3 2 + 1 = 1 。
路径
这是一个在原点处没有极限的函数:
f ( x , y ) = x y x 2 + y 2 , ( x , y ) ≠ ( 0 , 0 ) . f(x, y) = \frac{xy}{x^2 + y^2}, \qquad (x, y) \ne (0, 0). f ( x , y ) = x 2 + y 2 x y , ( x , y ) = ( 0 , 0 ) .
沿着四条直线趋近于原点,以 x = t x = t x = t 逐渐趋近于 0:
t t t f ( t , 0 ) f(t, 0) f ( t , 0 ) f ( t , t ) f(t, t) f ( t , t ) f ( t , 2 t ) f(t, 2t) f ( t , 2 t ) f ( t , − t ) f(t, -t) f ( t , − t ) 0.1 0.1 0.1 0 0 0 0.5 0.5 0.5 0.4 0.4 0.4 − 0.5 -0.5 − 0.5 0.01 0.01 0.01 0 0 0 0.5 0.5 0.5 0.4 0.4 0.4 − 0.5 -0.5 − 0.5 0.001 0.001 0.001 0 0 0 0.5 0.5 0.5 0.4 0.4 0.4 − 0.5 -0.5 − 0.5 − 0.001 -0.001 − 0.001 0 0 0 0.5 0.5 0.5 0.4 0.4 0.4 − 0.5 -0.5 − 0.5
沿每条直线,函数值完全不变,但不同直线间取值不同:沿 x x x 轴为 0,沿 y = x y = x y = x 为 0.5,沿 y = 2 x y = 2x y = 2 x 为 0.4,沿 − 0.5 -0.5 − 0.5 为 y = − x 。 y = -x\mathclose{\text{。}} y = − x 。 无论离原点多近,总存在接近 0.5 的值和接近 − 0.5 -0.5 − 0.5 的值,因此不存在满足定义 17.3 的单一数值 L 。 L\mathclose{\text{。}} L 。
定理 17.1沿路径取极限
设 lim ( x , y ) → ( a , b ) f ( x , y ) = L , \lim_{(x, y)\to(a, b)} f(x, y) = L\mathclose{\text{,}} lim ( x , y ) → ( a , b ) f ( x , y ) = L , 并设函数 x ( t ) 、 x(t)\mathclose{\text{、}} x ( t ) 、 y ( t ) y(t) y ( t ) 满足当 t → t 0 t \to t_0 t → t 0 时 x ( t ) → a 、 x(t) \to a\mathclose{\text{、}} x ( t ) → a 、 y ( t ) → b 。 y(t) \to b\mathclose{\text{。}} y ( t ) → b 。 再设当 t ≠ t 0 t \ne t_0 t = t 0 接近 t 0 t_0 t 0 时,( x ( t ) , y ( t ) ) \big(x(t), y(t)\big) ( x ( t ) , y ( t ) ) 属于 f f f 的定义域且不同于 ( a , b ) 。 (a, b)\mathclose{\text{。}} ( a , b ) 。 则
lim t → t 0 f ( x ( t ) , y ( t ) ) = L . \lim_{t\to t_0} f\big(x(t), y(t)\big) = L. t → t 0 lim f ( x ( t ) , y ( t ) ) = L .
所以如果 f f f 沿着两条这样的路径趋近于不同的数,或者沿着其中一条路径不趋近于任何数,则 lim ( x , y ) → ( a , b ) f ( x , y ) \lim_{(x, y)\to(a, b)} f(x, y) lim ( x , y ) → ( a , b ) f ( x , y ) 不存在。
证明
设 ε > 0 , \varepsilon > 0\mathclose{\text{,}} ε > 0 , 并取 δ \delta δ 如定义 17.3 所示。由于 t → t 0 , t \to t_0\mathclose{\text{,}} t → t 0 , 距离 ( x ( t ) − a ) 2 + ( y ( t ) − b ) 2 \sqrt{(x(t) - a)^2 + (y(t) - b)^2} ( x ( t ) − a ) 2 + ( y ( t ) − b ) 2 趋于 0,因此对于足够接近 t 0 t_0 t 0 的每个 t ≠ t 0 , t \ne t_0\mathclose{\text{,}} t = t 0 , 该距离都小于 δ ; \delta\mathclose{\text{;}} δ ; 并且在这些点上它不为 0,因为该点不是 ( a , b ) 。 (a, b)\mathclose{\text{。}} ( a , b ) 。 对于那些 t , t\mathclose{\text{,}} t , ∣ f ( x ( t ) , y ( t ) ) − L ∣ < ε , \abs{f(x(t), y(t)) - L} < \varepsilon\mathclose{\text{,}} ∣ f ( x ( t ) , y ( t )) − L ∣ < ε , 这是 lim t → t 0 f ( x ( t ) , y ( t ) ) = L \lim_{t\to t_0} f(x(t), y(t)) = L lim t → t 0 f ( x ( t ) , y ( t )) = L 所表示的含义。如果极限存在,则它沿每条路径都相同,但当两条路径给出不同数值时这是不可能的。
∎
例 17.3依赖路径的极限 ✓ 已检验
证明 lim ( x , y ) → ( 0 , 0 ) x y x 2 + y 2 \lim_{(x, y)\to(0, 0)} \dfrac{xy}{x^2 + y^2} lim ( x , y ) → ( 0 , 0 ) x 2 + y 2 x y 不存在。
沿着直线 y = m x , y = mx\mathclose{\text{,}} y = m x , 带 x ≠ 0 , x \ne 0\mathclose{\text{,}} x = 0 ,
f ( x , m x ) = x ⋅ m x x 2 + m 2 x 2 = m x 2 ( 1 + m 2 ) x 2 = m 1 + m 2 . f(x, mx) = \frac{x \cdot mx}{x^2 + m^2x^2} = \frac{m x^2}{(1 + m^2)x^2} = \frac{m}{1 + m^2}. f ( x , m x ) = x 2 + m 2 x 2 x ⋅ m x = ( 1 + m 2 ) x 2 m x 2 = 1 + m 2 m .
所以 f f f 在通过原点的每条直线上都是常数:0 沿着 x x x 轴(m = 0 ), m = 0\mathclose{\text{),}} m = 0 ), 而 1 2 \tfrac12 2 1 沿着 y = x y = x y = x (m = 1 )。 m = 1\mathclose{\text{)。}} m = 1 )。 两条路径给出不同的极限,因此根据定理 17.1,极限不存在。在原点附近,图像是一个扭曲的曲面:从 − 1 2 -\tfrac12 − 2 1 到 1 2 \tfrac12 2 1 (即 m / ( 1 + m 2 ) m/(1 + m^2) m / ( 1 + m 2 ) 的取值范围)的每一个值,都在通过原点的整条直线上被取到,且可以任意接近原点。
注意
沿着每一条直线一致并不证明极限存在。对于 g ( x , y ) = x 2 y x 4 + y 2 , g(x, y) = \dfrac{x^2 y}{x^4 + y^2}\mathclose{\text{,}} g ( x , y ) = x 4 + y 2 x 2 y , 通过原点的每一条直线都给出极限 0:沿 y = m x , y = mx\mathclose{\text{,}} y = m x , g = m x x 2 + m 2 , g = \dfrac{mx}{x^2 + m^2}\mathclose{\text{,}} g = x 2 + m 2 m x , 其趋于 0(对于 m = 0 m = 0 m = 0 也是 0),沿 y y y 轴 g = 0 。 g = 0\mathclose{\text{。}} g = 0 。 但沿抛物线 y = x 2 , y = x^2\mathclose{\text{,}} y = x 2 , g = x 4 2 x 4 = 1 2 。 g = \dfrac{x^4}{2x^4} = \dfrac12\mathclose{\text{。}} g = 2 x 4 x 4 = 2 1 。 极限不存在。要证明极限存在,你需要一个覆盖所有接近 ( a , b ) (a, b) ( a , b ) 的点的论证。
夹逼法
第 2.6 节 的夹逼定理可用于这样的论证。
定理 17.2二维中的夹逼定理
假设 ∣ f ( x , y ) − L ∣ ≤ g ( x , y ) \abs{f(x, y) - L} \le g(x, y) ∣ f ( x , y ) − L ∣ ≤ g ( x , y ) 对于以 ( a , b ) (a, b) ( a , b ) 为中心的圆盘内的每一个点 ( x , y ) ≠ ( a , b ) , (x, y) \ne (a, b)\mathclose{\text{,}} ( x , y ) = ( a , b ) , 且 lim ( x , y ) → ( a , b ) g ( x , y ) = 0 。 \lim_{(x, y)\to(a, b)} g(x, y) = 0\mathclose{\text{。}} lim ( x , y ) → ( a , b ) g ( x , y ) = 0 。 那么 lim ( x , y ) → ( a , b ) f ( x , y ) = L 。 \lim_{(x, y)\to(a, b)} f(x, y) = L\mathclose{\text{。}} lim ( x , y ) → ( a , b ) f ( x , y ) = L 。
证明
设 ε > 0 。 \varepsilon > 0\mathclose{\text{。}} ε > 0 。 由于 g → 0 , g \to 0\mathclose{\text{,}} g → 0 , 存在一个 δ > 0 , \delta > 0\mathclose{\text{,}} δ > 0 , 可以取不超过圆盘的半径,使得 g ( x , y ) < ε g(x, y) < \varepsilon g ( x , y ) < ε 当 0 < ( x − a ) 2 + ( y − b ) 2 < δ 0 < \sqrt{(x - a)^2 + (y - b)^2} < \delta 0 < ( x − a ) 2 + ( y − b ) 2 < δ 时成立。对于这些点, ∣ f ( x , y ) − L ∣ ≤ g ( x , y ) < ε 。 \abs{f(x, y) - L} \le g(x, y) < \varepsilon\mathclose{\text{。}} ∣ f ( x , y ) − L ∣ ≤ g ( x , y ) < ε 。
∎
例 17.4通过夹逼法求极限 ✓ 已检验
求 lim ( x , y ) → ( 0 , 0 ) 3 x 2 y x 2 + y 2 。 \lim_{(x, y)\to(0, 0)} \dfrac{3x^2 y}{x^2 + y^2}\mathclose{\text{。}} lim ( x , y ) → ( 0 , 0 ) x 2 + y 2 3 x 2 y 。
沿着线 y = m x y = mx y = m x 函数是 3 m x 3 ( 1 + m 2 ) x 2 = 3 m x 1 + m 2 , \dfrac{3m x^3}{(1 + m^2)x^2} = \dfrac{3m x}{1 + m^2}\mathclose{\text{,}} ( 1 + m 2 ) x 2 3 m x 3 = 1 + m 2 3 m x , 趋于 0,且沿 y y y 轴其值为 0。因此如果极限存在,则为 0(定理 17.1)。为证明其存在,使用夹逼定理。对于 ( x , y ) ≠ ( 0 , 0 ) , (x, y) \ne (0, 0)\mathclose{\text{,}} ( x , y ) = ( 0 , 0 ) , x 2 ≤ x 2 + y 2 , x^2 \le x^2 + y^2\mathclose{\text{,}} x 2 ≤ x 2 + y 2 , 所以 x 2 x 2 + y 2 ≤ 1 \dfrac{x^2}{x^2 + y^2} \le 1 x 2 + y 2 x 2 ≤ 1 和
∣ 3 x 2 y x 2 + y 2 − 0 ∣ = 3 ∣ y ∣ x 2 x 2 + y 2 ≤ 3 ∣ y ∣ . \abs{\frac{3x^2 y}{x^2 + y^2} - 0} = 3\abs{y}\,\frac{x^2}{x^2 + y^2} \le 3\abs{y}. x 2 + y 2 3 x 2 y − 0 = 3 ∣ y ∣ x 2 + y 2 x 2 ≤ 3 ∣ y ∣ .
如 ( x , y ) → ( 0 , 0 ) , (x, y) \to (0, 0)\mathclose{\text{,}} ( x , y ) → ( 0 , 0 ) , 3 ∣ y ∣ → 0 , 3\abs{y} \to 0\mathclose{\text{,}} 3 ∣ y ∣ → 0 , 因为 ∣ y ∣ ≤ x 2 + y 2 。 \abs{y} \le \sqrt{x^2 + y^2}\mathclose{\text{。}} ∣ y ∣ ≤ x 2 + y 2 。 根据定理 17.2,极限为 0。用 ε–δ 术语, δ = ε / 3 \delta = \varepsilon/3 δ = ε /3 成立: x 2 + y 2 < ε / 3 \sqrt{x^2 + y^2} < \varepsilon/3 x 2 + y 2 < ε /3 给出 3 ∣ y ∣ < ε 。 3\abs{y} < \varepsilon\mathclose{\text{。}} 3 ∣ y ∣ < ε 。
连续性
定义 17.4连续性
设 f f f 定义在以 ( a , b ) (a, b) ( a , b ) 为圆心的一个圆盘上。若满足下式,则 f f f 在 ( a , b ) (a, b) ( a , b ) 处连续 :
lim ( x , y ) → ( a , b ) f ( x , y ) = f ( a , b ) . \lim_{(x, y)\to(a, b)} f(x, y) = f(a, b). ( x , y ) → ( a , b ) lim f ( x , y ) = f ( a , b ) .
若 在集合 上连续,则其在该集合的每一点处连续(在定义域边缘的点,极限取定义域内的点)。
如模块 3 ]所述,连续函数的和、积、商(分母不为 0)都是连续的,复合函数也是如此:如果 g ( x , y ) g(x, y) g ( x , y ) 在 ( a , b ) (a, b) ( a , b ) 处连续,且一个变量函数 h h h 在 g ( a , b ) g(a, b) g ( a , b ) 处连续,则 h ( g ( x , y ) ) h\big(g(x, y)\big) h ( g ( x , y ) ) 在 ( a , b ) (a, b) ( a , b ) 处连续。由于 x x x 和 y y y 本身是连续的,因此所有关于 x x x 和 y y y 的多项式函数在全定义域内连续,所有有理函数在其分母不为 0 的地方连续,以及如 e x y sin y e^{xy}\sin y e x y sin y 和 ln ( x 2 + y 2 ) \ln(x^2 + y^2) ln ( x 2 + y 2 ) 这样的函数在其定义域内连续。
在公式失效的点上,仔细观察。例 17.3 和 17.4 中的函数在原点处均未定义。在原点处给每个函数赋予值 0:例 17.4 中的函数在原点处连续,因为其在原点处的极限为 0,而例 17.3 中的函数在原点处不连续,因为其在该点处无极限。此内容将在第 17.4 节中再次提及,作为警告。
取一个半径为 r = 3 r = 3 r = 3 cm、高为 h = 10 h = 10 h = 10 cm 的圆柱形罐子,体积为 V ( 3 , 10 ) = 90 π ≈ 282.7 V(3, 10) = 90\pi \approx 282.7 V ( 3 , 10 ) = 90 π ≈ 282.7 cm³。当半径变化而高度不变时,体积如何变化?将罐子加宽 Δ \Delta Δ cm,或使其增高 Δ \Delta Δ cm,并将每次体积变化除以 Δ : \Delta\mathclose{\text{:}} Δ :
Δ \Delta Δ V ( 3 + Δ , 10 ) − V ( 3 , 10 ) Δ \dfrac{V(3 + \Delta, 10) - V(3, 10)}{\Delta} Δ V ( 3 + Δ , 10 ) − V ( 3 , 10 ) V ( 3 , 10 + Δ ) − V ( 3 , 10 ) Δ \dfrac{V(3, 10 + \Delta) - V(3, 10)}{\Delta} Δ V ( 3 , 10 + Δ ) − V ( 3 , 10 ) 1 1 1 219.911 219.911 219.911 28.2743 28.2743 28.2743 0.1 0.1 0.1 191.637 191.637 191.637 28.2743 28.2743 28.2743 0.01 0.01 0.01 188.810 188.810 188.810 28.2743 28.2743 28.2743 0.001 0.001 0.001 188.527 188.527 188.527 28.2743 28.2743 28.2743 − 0.001 -0.001 − 0.001 188.464 188.464 188.464 28.2743 28.2743 28.2743
保持高度为 10,V = 10 π r 2 V = 10\pi r^2 V = 10 π r 2 是 r r r 的函数,第一列趋近于其在 r = 3 、 r = 3\mathclose{\text{、}} r = 3 、 20 π r = 60 π ≈ 188.5 20\pi r = 60\pi \approx 188.5 20 π r = 60 π ≈ 188.5 处的导数。保持半径为 3,V = 9 π h V = 9\pi h V = 9 π h 是 h h h 的线性函数,第二列是其斜率 9 π ≈ 28.27 , 9\pi \approx 28.27\mathclose{\text{,}} 9 π ≈ 28.27 , 无论 Δ \Delta Δ 为何值。这两个数是 偏导数 ,即 V V V 在 ( 3 , 10 ) (3, 10) ( 3 , 10 ) 处的偏导数:在该尺寸附近,体积随半径每增加 1 厘米而增加约 188.5 立方厘米,随高度每增加 1 厘米而增加约 28.3 立方厘米。扩大罐体的体积增长速度比延长罐体快六倍以上。
定义 17.5偏导数
设二元函数 f f f 定义在以 ( a , b ) (a, b) ( a , b ) 为圆心的一个圆盘上。f f f 在 ( a , b ) (a, b) ( a , b ) 处对 x x x 的偏导数 为
f x ( a , b ) = lim h → 0 f ( a + h , b ) − f ( a , b ) h , f_x(a, b) = \lim_{h\to0}\frac{f(a + h, b) - f(a, b)}{h}, f x ( a , b ) = h → 0 lim h f ( a + h , b ) − f ( a , b ) ,
而对 y y y 的偏导数 为
f y ( a , b ) = lim h → 0 f ( a , b + h ) − f ( a , b ) h , f_y(a, b) = \lim_{h\to0}\frac{f(a, b + h) - f(a, b)}{h}, f y ( a , b ) = h → 0 lim h f ( a , b + h ) − f ( a , b ) ,
该结果成立的条件是极限存在。
f x f_x f x 读作 “f 下标 x”。其他记号:∂ f ∂ x \dfrac{\partial f}{\partial x} ∂ x ∂ f 读作 “对 x 求偏导的 f”(圆弧符号 ∂ \partial ∂ 读作 “偏导”,表示 f f f 有其他变量被固定),而 ∂ z ∂ x \dfrac{\partial z}{\partial x} ∂ x ∂ z 当 z = f ( x , y ) 。 z = f(x, y)\mathclose{\text{。}} z = f ( x , y ) 。 让点变化得到两个新的二元函数 f x ( x , y ) f_x(x, y) f x ( x , y ) 和 f y ( x , y ) 。 f_y(x, y)\mathclose{\text{。}} f y ( x , y ) 。
定义说明 f x ( a , b ) f_x(a, b) f x ( a , b ) 是函数 x ↦ f ( x , b ) x \mapsto f(x, b) x ↦ f ( x , b ) 关于 a a a 的普通导数,其中 y y y 在 b b b 处被固定。这给出了计算偏导数的规则。
要点
求 f x f_x f x 时,将 y y y 视为常数,按 Modules 4 到 6 的规则对 x x x 求导。求 f y f_y f y 时,将 x x x 视为常数,对 y y y 求导。
从几何上看,竖直平面 y = b y = b y = b 与曲面 z = f ( x , y ) z = f(x, y) z = f ( x , y ) 相交于曲线 z = f ( x , b ) , z = f(x, b)\mathclose{\text{,}} z = f ( x , b ) , f x ( a , b ) f_x(a, b) f x ( a , b ) 就是这条曲线在点 P ( a , b , f ( a , b ) ) P(a, b, f(a, b)) P ( a , b , f ( a , b )) 处的斜率,表示从 P P P 沿 x x x 轴正向移动时,曲面的升高率。类似地,f y ( a , b ) f_y(a, b) f y ( a , b ) 是由平面 x = a x = a x = a 截出的曲线的斜率(图 17.2 左)。对 f ( x , y ) = 6 − x 2 − 2 y 2 f(x, y) = 6 - x^2 - 2y^2 f ( x , y ) = 6 − x 2 − 2 y 2 在 P ( 1 , 1 , 3 ) P(1, 1, 3) P ( 1 , 1 , 3 ) 处,平面 y = 1 y = 1 y = 1 截出曲线 z = 4 − x 2 , z = 4 - x^2\mathclose{\text{,}} z = 4 − x 2 , 在 x = 1 x = 1 x = 1 处的斜率为 − 2 x = − 2 。 -2x = -2\mathclose{\text{。}} − 2 x = − 2 。 平面 x = 1 x = 1 x = 1 截出曲线 z = 5 − 2 y 2 , z = 5 - 2y^2\mathclose{\text{,}} z = 5 − 2 y 2 , 在 y = 1 y = 1 y = 1 处的斜率为 − 4 y = − 4 。 -4y = -4\mathclose{\text{。}} − 4 y = − 4 。 所以 f x ( 1 , 1 ) = − 2 , f_x(1, 1) = -2\mathclose{\text{,}} f x ( 1 , 1 ) = − 2 , 且 f y ( 1 , 1 ) = − 4 。 f_y(1, 1) = -4\mathclose{\text{。}} f y ( 1 , 1 ) = − 4 。 由求导法则,处处有 f x = − 2 x f_x = -2x f x = − 2 x 和 f y = − 4 y 。 f_y = -4y\mathclose{\text{。}} f y = − 4 y 。
图 17.2 左:曲面 z = 6 − x 2 − 2 y 2 z = 6 - x^2 - 2y^2 z = 6 − x 2 − 2 y 2 和点 P ( 1 , 1 , 3 ) 。 P(1, 1, 3)\mathclose{\text{。}} P ( 1 , 1 , 3 ) 。 平面 y = 1 y = 1 y = 1 截出蓝色曲线 z = 4 − x 2 , z = 4 - x^2\mathclose{\text{,}} z = 4 − x 2 , 其在点 P P P (暗色)处的切线斜率为 f x ( 1 , 1 ) = − 2 ; f_x(1, 1) = -2\mathclose{\text{;}} f x ( 1 , 1 ) = − 2 ; 平面 x = 1 x = 1 x = 1 截出橙色曲线 z = 5 − 2 y 2 , z = 5 - 2y^2\mathclose{\text{,}} z = 5 − 2 y 2 , 其切线(红色)斜率为 f y ( 1 , 1 ) = − 4 。 f_y(1, 1) = -4\mathclose{\text{。}} f y ( 1 , 1 ) = − 4 。 右:点 P P P 处的切平面 z = 9 − 2 x − 4 y z = 9 - 2x - 4y z = 9 − 2 x − 4 y (第 17.4 节)包含这两条切线。
计算偏导数
例 17.5依据规则计算偏导数 ✓ 已检验
求(a)曲面 f ( x , y ) = x 3 y 2 − 5 x y + 2 y 3 f(x, y) = x^3y^2 - 5xy + 2y^3 f ( x , y ) = x 3 y 2 − 5 x y + 2 y 3 的偏导数及其在点 ( 1 , 2 ) (1, 2) ( 1 , 2 ) 处的值,(b)曲面 g ( x , y ) = sin ( x y 2 ) g(x, y) = \sin(xy^2) g ( x , y ) = sin ( x y 2 ) 和(c)曲线 q ( x , y ) = x x 2 + y 2 q(x, y) = \dfrac{x}{x^2 + y^2} q ( x , y ) = x 2 + y 2 x 的偏导数。
(a) 保持 y y y 不变时, y 2 y^2 y 2 是 x 3 y 2 x^3y^2 x 3 y 2 的常数因子, − 5 y -5y − 5 y 是 x x x 的常数因子, 2 y 3 2y^3 2 y 3 是常数:
f x = 3 x 2 y 2 − 5 y , f y = 2 x 3 y − 5 x + 6 y 2 . f_x = 3x^2y^2 - 5y, \qquad f_y = 2x^3y - 5x + 6y^2. f x = 3 x 2 y 2 − 5 y , f y = 2 x 3 y − 5 x + 6 y 2 .
在 ( 1 , 2 ) : (1, 2)\mathclose{\text{:}} ( 1 , 2 ) : f x ( 1 , 2 ) = 12 − 10 = 2 f_x(1, 2) = 12 - 10 = 2 f x ( 1 , 2 ) = 12 − 10 = 2 和 f y ( 1 , 2 ) = 4 − 5 + 24 = 23 。 f_y(1, 2) = 4 - 5 + 24 = 23\mathclose{\text{。}} f y ( 1 , 2 ) = 4 − 5 + 24 = 23 。
(b) 由链式法则,内函数为 x y 2 , xy^2\mathclose{\text{,}} x y 2 , 其偏导数为 y 2 y^2 y 2 和 2 x y : 2xy\mathclose{\text{:}} 2 x y :
g x = y 2 cos ( x y 2 ) , g y = 2 x y cos ( x y 2 ) . g_x = y^2\cos(xy^2), \qquad g_y = 2xy\cos(xy^2). g x = y 2 cos ( x y 2 ) , g y = 2 x y cos ( x y 2 ) .
(c) 根据商的法则。当 y y y 为常数时,分母的导数是 2 x , 2x\mathclose{\text{,}} 2 x , 因此
q x = ( x 2 + y 2 ) − x ⋅ 2 x ( x 2 + y 2 ) 2 = y 2 − x 2 ( x 2 + y 2 ) 2 . \begin{aligned} q_x &= \frac{(x^2 + y^2) - x \cdot 2x}{(x^2 + y^2)^2} \\ &= \frac{y^2 - x^2}{(x^2 + y^2)^2}. \end{aligned} q x = ( x 2 + y 2 ) 2 ( x 2 + y 2 ) − x ⋅ 2 x = ( x 2 + y 2 ) 2 y 2 − x 2 .
当 x x x 为常数时,分子是一个常数,因此
q y = − x ⋅ 2 y ( x 2 + y 2 ) 2 = − 2 x y ( x 2 + y 2 ) 2 , q_y = -\frac{x \cdot 2y}{(x^2 + y^2)^2} = -\frac{2xy}{(x^2 + y^2)^2}, q y = − ( x 2 + y 2 ) 2 x ⋅ 2 y = − ( x 2 + y 2 ) 2 2 x y ,
对于 ( x , y ) ≠ ( 0 , 0 ) (x, y) \ne (0, 0) ( x , y ) = ( 0 , 0 ) 都是如此。
注意
当对 x x x 求导时,包含仅 y y y 的因子是一个常数:即 ∂ ∂ x ( x 3 y 2 ) = 3 x 2 y 2 , \dfrac{\partial}{\partial x}\big(x^3y^2\big) = 3x^2y^2\mathclose{\text{,}} ∂ x ∂ ( x 3 y 2 ) = 3 x 2 y 2 , 而不是 3 x 2 y 2 + 2 x 3 y , 3x^2y^2 + 2x^3y\mathclose{\text{,}} 3 x 2 y 2 + 2 x 3 y , 以及 ∂ ∂ x ( y 3 ) = 0 。 \dfrac{\partial}{\partial x}\big(y^3\big) = 0\mathclose{\text{。}} ∂ x ∂ ( y 3 ) = 0 。 只有当两个因子都包含 x x x 时,才需要使用乘积法则。
对于一个三变量函数,f x 、 f_x\mathclose{\text{、}} f x 、 f y f_y f y 和 f z f_z f z 定义方式相同,每个都保持另外两个变量固定。对于 w = x y 2 z 3 : w = xy^2z^3\mathclose{\text{:}} w = x y 2 z 3 : w x = y 2 z 3 、 w_x = y^2z^3\mathclose{\text{、}} w x = y 2 z 3 、 w y = 2 x y z 3 w_y = 2xyz^3 w y = 2 x y z 3 和 w z = 3 x y 2 z 2 。 w_z = 3xy^2z^2\mathclose{\text{。}} w z = 3 x y 2 z 2 。
高阶偏导数
偏导数 f x f_x f x 和 f y f_y f y 仍然是 x x x 和 y y y 的函数。在这些偏导数存在的情况下,它们是 f f f 的四个 二阶偏导数 。
f x x = ( f x ) x = ∂ 2 f ∂ x 2 , f x y = ( f x ) y = ∂ 2 f ∂ y ∂ x , f y x = ( f y ) x = ∂ 2 f ∂ x ∂ y , f y y = ( f y ) y = ∂ 2 f ∂ y 2 . \begin{aligned} f_{xx} &= (f_x)_x = \frac{\partial^2 f}{\partial x^2}, & f_{xy} &= (f_x)_y = \frac{\partial^2 f}{\partial y\,\partial x}, \\ f_{yx} &= (f_y)_x = \frac{\partial^2 f}{\partial x\,\partial y}, & f_{yy} &= (f_y)_y = \frac{\partial^2 f}{\partial y^2}. \end{aligned} f xx f y x = ( f x ) x = ∂ x 2 ∂ 2 f , = ( f y ) x = ∂ x ∂ y ∂ 2 f , f x y f y y = ( f x ) y = ∂ y ∂ x ∂ 2 f , = ( f y ) y = ∂ y 2 ∂ 2 f .
f x y f_{xy} f x y 读作「f 下标 x y」。注意求导顺序。f x y f_{xy} f x y 的下标从左向右读,先对 x x x 求导,再对 y y y 求导。表示同一导数的 ∂ 2 f ∂ y ∂ x \dfrac{\partial^2 f}{\partial y\,\partial x} ∂ y ∂ x ∂ 2 f 按从右向左的顺序读。f x y f_{xy} f x y 和 f y x f_{yx} f y x 称为混合偏导数 。
例 17.6第二偏导数 ✓ 已检验
求f ( x , y ) = x 3 y 2 − 5 x y + 2 y 3 f(x, y) = x^3y^2 - 5xy + 2y^3 f ( x , y ) = x 3 y 2 − 5 x y + 2 y 3 (例17.5)的四个二阶偏导数,以及g ( x , y ) = sin ( x y 2 ) g(x, y) = \sin(xy^2) g ( x , y ) = sin ( x y 2 ) 的混合偏导数。
由f x = 3 x 2 y 2 − 5 y f_x = 3x^2y^2 - 5y f x = 3 x 2 y 2 − 5 y 和f y = 2 x 3 y − 5 x + 6 y 2 f_y = 2x^3y - 5x + 6y^2 f y = 2 x 3 y − 5 x + 6 y 2 可得:
f x x = 6 x y 2 , f x y = 6 x 2 y − 5 , f y x = 6 x 2 y − 5 , f y y = 2 x 3 + 12 y . \begin{aligned} f_{xx} &= 6xy^2, & f_{xy} &= 6x^2y - 5, \\ f_{yx} &= 6x^2y - 5, & f_{yy} &= 2x^3 + 12y. \end{aligned} f xx f y x = 6 x y 2 , = 6 x 2 y − 5 , f x y f y y = 6 x 2 y − 5 , = 2 x 3 + 12 y .
对于 g , g\mathclose{\text{,}} g , 对 g x = y 2 cos ( x y 2 ) g_x = y^2\cos(xy^2) g x = y 2 cos ( x y 2 ) 关于 y y y 求导,对 g y = 2 x y cos ( x y 2 ) g_y = 2xy\cos(xy^2) g y = 2 x y cos ( x y 2 ) 关于 x x x 求导,每次均使用乘积法则和链式法则:
g x y = 2 y cos ( x y 2 ) − y 2 sin ( x y 2 ) ⋅ 2 x y = 2 y cos ( x y 2 ) − 2 x y 3 sin ( x y 2 ) , g y x = 2 y cos ( x y 2 ) − 2 x y sin ( x y 2 ) ⋅ y 2 = 2 y cos ( x y 2 ) − 2 x y 3 sin ( x y 2 ) . \begin{aligned} g_{xy} &= 2y\cos(xy^2) - y^2\sin(xy^2)\cdot 2xy \\ &= 2y\cos(xy^2) - 2xy^3\sin(xy^2), \\ g_{yx} &= 2y\cos(xy^2) - 2xy\sin(xy^2)\cdot y^2 \\ &= 2y\cos(xy^2) - 2xy^3\sin(xy^2). \end{aligned} g x y g y x = 2 y cos ( x y 2 ) − y 2 sin ( x y 2 ) ⋅ 2 x y = 2 y cos ( x y 2 ) − 2 x y 3 sin ( x y 2 ) , = 2 y cos ( x y 2 ) − 2 x y sin ( x y 2 ) ⋅ y 2 = 2 y cos ( x y 2 ) − 2 x y 3 sin ( x y 2 ) .
两次混合偏导数一致,尽管它们是通过不同的方法计算得到的。
这种一致并非偶然。
定理 17.3克莱罗定理
设 f f f 定义在包含点 ( a , b ) (a, b) ( a , b ) 的圆盘 D D D 上。若函数 f x y f_{xy} f x y 和 f y x f_{yx} f y x 在 D D D 上都连续,则 f x y ( a , b ) = f y x ( a , b ) 。 f_{xy}(a, b) = f_{yx}(a, b)\mathclose{\text{。}} f x y ( a , b ) = f y x ( a , b ) 。
混合偏导数在例题 17.5 和 17.6 中,只要函数有定义,它们在定义域内是连续的,因此在这些地方求导的顺序无关紧要。这个条件不能省略:练习 17.10 给出一个函数,它具有 f x y ( 0 , 0 ) = − 1 f_{xy}(0, 0) = -1 f x y ( 0 , 0 ) = − 1 但不具有 f y x ( 0 , 0 ) = 1 。 f_{yx}(0, 0) = 1\mathclose{\text{。}} f y x ( 0 , 0 ) = 1 。 这个定理可以推广到更高阶导数:例如,对于一个圆盘上的点,只要所有三阶偏导数存在且连续,则 f x y y = f y x y = f y y x f_{xyy} = f_{yxy} = f_{yyx} f x y y = f y x y = f y y x 成立。
深入一步拉格朗日定理的证明
第一次阅读可以跳过这个证明。它使用了中值定理(定理 8.4 )四次。对于一个非常小的 h ≠ 0 , h \ne 0\mathclose{\text{,}} h = 0 , 小到以 ( a , b ) (a, b) ( a , b ) 和 ( a + h , b + h ) (a + h, b + h) ( a + h , b + h ) 为顶点的正方形位于 D D D 内,考虑四个值的组合
Δ ( h ) = f ( a + h , b + h ) − f ( a + h , b ) − f ( a , b + h ) + f ( a , b ) . \begin{aligned} \Delta(h) &= f(a + h, b + h) - f(a + h, b) \\ &\quad - f(a, b + h) + f(a, b). \end{aligned} Δ ( h ) = f ( a + h , b + h ) − f ( a + h , b ) − f ( a , b + h ) + f ( a , b ) .
第一组。 设 G ( x ) = f ( x , b + h ) − f ( x , b ) , G(x) = f(x, b + h) - f(x, b)\mathclose{\text{,}} G ( x ) = f ( x , b + h ) − f ( x , b ) , 使得 Δ ( h ) = G ( a + h ) − G ( a ) 。 \Delta(h) = G(a + h) - G(a)\mathclose{\text{。}} Δ ( h ) = G ( a + h ) − G ( a ) 。 偏导数 f x f_x f x 在 D D D 上存在(否则 f x y f_{xy} f x y 在那里不存在),因此 G G G 是可微的,且 G ′ ( x ) = f x ( x , b + h ) − f x ( x , b ) 。 G'(x) = f_x(x, b + h) - f_x(x, b)\mathclose{\text{。}} G ′ ( x ) = f x ( x , b + h ) − f x ( x , b ) 。 根据中值定理,存在一个数 c c c 在 a a a 和 a + h a + h a + h 之间,使得
Δ ( h ) = h G ′ ( c ) = h ( f x ( c , b + h ) − f x ( c , b ) ) . \begin{aligned} \Delta(h) &= h\,G'(c) \\ &= h\big(f_x(c, b + h) - f_x(c, b)\big). \end{aligned} Δ ( h ) = h G ′ ( c ) = h ( f x ( c , b + h ) − f x ( c , b ) ) .
函数 y ↦ f x ( c , y ) y \mapsto f_x(c, y) y ↦ f x ( c , y ) 的导数是 f x y ( c , y ) , f_{xy}(c, y)\mathclose{\text{,}} f x y ( c , y ) , 因此根据中值定理,存在一个数 d d d 在 b b b 与 b + h b + h b + h 之间,使得 f x ( c , b + h ) − f x ( c , b ) = h f x y ( c , d ) 。 f_x(c, b + h) - f_x(c, b) = h\,f_{xy}(c, d)\mathclose{\text{。}} f x ( c , b + h ) − f x ( c , b ) = h f x y ( c , d ) 。 所以 Δ ( h ) = h 2 f x y ( c , d ) 。 \Delta(h) = h^2 f_{xy}(c, d)\mathclose{\text{。}} Δ ( h ) = h 2 f x y ( c , d ) 。
第二组。 设 H ( y ) = f ( a + h , y ) − f ( a , y ) , H(y) = f(a + h, y) - f(a, y)\mathclose{\text{,}} H ( y ) = f ( a + h , y ) − f ( a , y ) , 使得 Δ ( h ) = H ( b + h ) − H ( b ) 。 \Delta(h) = H(b + h) - H(b)\mathclose{\text{。}} Δ ( h ) = H ( b + h ) − H ( b ) 。 同样的两步,首先在 y , y\mathclose{\text{,}} y , 然后在 x , x\mathclose{\text{,}} x , 得到数 c ′ c' c ′ 和 d ′ , d'\mathclose{\text{,}} d ′ , 分别在 ∣ h ∣ \abs{h} ∣ h ∣ 附近 a a a 和 b , b\mathclose{\text{,}} b , 使得 Δ ( h ) = h 2 f y x ( c ′ , d ′ ) 。 \Delta(h) = h^2 f_{yx}(c', d')\mathclose{\text{。}} Δ ( h ) = h 2 f y x ( c ′ , d ′ ) 。
因此f x y ( c , d ) = f y x ( c ′ , d ′ ) f_{xy}(c, d) = f_{yx}(c', d') f x y ( c , d ) = f y x ( c ′ , d ′ ) 对于每个小h ≠ 0 。 h \ne 0\mathclose{\text{。}} h = 0 。 如h → 0 h \to 0 h → 0 所示,当点( c , d ) (c, d) ( c , d ) 和( c ′ , d ′ ) (c', d') ( c ′ , d ′ ) 都趋近于( a , b ) (a, b) ( a , b ) 时,由于f x y f_{xy} f x y 和f y x f_{yx} f y x 在该处连续,两侧分别趋近于f x y ( a , b ) f_{xy}(a, b) f x y ( a , b ) 和f y x ( a , b ) 。 f_{yx}(a, b)\mathclose{\text{。}} f y x ( a , b ) 。 等量有相等的极限。
许多物理定律是偏导数之间的方程,称为 偏微分方程 。对于一根细长、均匀且侧面绝缘、无内部热源的杆,温度 u ( x , t ) u(x, t) u ( x , t ) 由 热方程 u t = k u x x u_t = k\,u_{xx} u t = k u xx 描述,其中常数 k > 0 k > 0 k > 0 由材料决定。对于一个细长、均匀且两面绝缘、无内部热源的薄板,稳定温度满足拉普拉斯方程 u x x + u y y = 0 u_{xx} + u_{yy} = 0 u xx + u y y = 0 (练习 17.9)。求解此类方程超出了本课程范围,但验证一个解只需使用偏导数: u = e − t sin x u = e^{-t}\sin x u = e − t sin x 满足热方程,因为 k = 1 , k = 1\mathclose{\text{,}} k = 1 , 由于 u t = − e − t sin x u_t = -e^{-t}\sin x u t = − e − t sin x 和 u x x = − e − t sin x 。 u_{xx} = -e^{-t}\sin x\mathclose{\text{。}} u xx = − e − t sin x 。
动手计算偏导数与 SymPy
sp.diff 计算偏导数:指定变量名称,SymPy 保持其他变量固定。连续多个变量表示高阶导数,按书写顺序依次计算:
Python 复制
import sympy as sp
x, y = sp.symbols ('x y' )
f = x**3 *y**2 - 5 *x*y + 2 *y**3 # Example 17.5
print (sp.diff (f, x), '|' , sp.diff (f, y))
print (sp.diff (f, x, y), '|' , sp.diff (f, y, x)) # f_xy and f_yx
print (sp.diff (f, x).subs ({x: 1 , y: 2 })) # f_x(1, 2)
输出
3*x**2*y**2 - 5*y | 2*x**3*y - 5*x + 6*y**2
6*x**2*y - 5 | 6*x**2*y - 5
2
sp.diff(f, x, y) 首先对 x x x 求导,然后对 y y y 求导:结果为 f x y 。 f_{xy}\mathclose{\text{。}} f x y 。 重复的变量可以用次数表示: sp.diff(f, x, 2) 是 f x x 。 f_{xx}\mathclose{\text{。}} f xx 。 本节开头的示例:
Python 复制
r, h = sp.symbols ('r h' , positive=True )
V = sp.pi*r**2 *h
print (sp.diff (V, r), '|' , sp.diff (V, h))
Vr = sp.diff (V, r).subs ({r: 3 , h: 10 }) # V_r(3, 10)
print (Vr, '=' , sp.N (Vr))
输出
2*pi*h*r | pi*r**2
60*pi = 188.495559215388
SymPy 将 2 π r h 2\pi rh 2 π r h 写作 2*pi*h*r,其中因子的顺序是它自己的顺序。在 ( 3 , 10 ) (3, 10) ( 3 , 10 ) 处,它为 60 π ≈ 188.5 , 60\pi \approx 188.5\mathclose{\text{,}} 60 π ≈ 188.5 , 即本节开头表格中第一列所趋近的数。
放大一个一元可导函数的图像,它会越来越像一条直线,即它的切线;第7.2节 将其转化为线性近似。放大一个光滑曲面,它会越来越像一个平面,即它的 切平面 。
哪个平面?通过点 P ( a , b , c ) P(a, b, c) P ( a , b , c ) 且不垂直的平面,其方程为 z − c = A ( x − a ) + B ( y − b ) z - c = A(x - a) + B(y - b) z − c = A ( x − a ) + B ( y − b ) (模块16)。垂直平面 y = b y = b y = b 将它沿着直线 z − c = A ( x − a ) z - c = A(x - a) z − c = A ( x − a ) 剖开,该直线的斜率为 A 。 A\mathclose{\text{。}} A 。 如果平面要与曲面在 P P P 处相切,这条直线应为同一垂直平面从曲面中截出的曲线的切线,其斜率为 f x ( a , b ) 。 f_x(a, b)\mathclose{\text{。}} f x ( a , b ) 。 因此 A = f x ( a , b ) , A = f_x(a, b)\mathclose{\text{,}} A = f x ( a , b ) , 同理 B = f y ( a , b ) : B = f_y(a, b)\mathclose{\text{:}} B = f y ( a , b ) : 切平面是图17.2中两条切线所确定的平面。
定义 17.6切平面
假设 f f f 在以 ( a , b ) (a, b) ( a , b ) 为中心的圆盘上存在偏导数,并且在 ( a , b ) (a, b) ( a , b ) 处连续。曲面 z = f ( x , y ) z = f(x, y) z = f ( x , y ) 在点 P ( a , b , f ( a , b ) ) P(a, b, f(a, b)) P ( a , b , f ( a , b )) 处的 切平面 是以下平面
z = f ( a , b ) + f x ( a , b ) ( x − a ) + f y ( a , b ) ( y − b ) . \begin{aligned} z = f(a, b) &+ f_x(a, b)(x - a) \\ &+ f_y(a, b)(y - b). \end{aligned} z = f ( a , b ) + f x ( a , b ) ( x − a ) + f y ( a , b ) ( y − b ) .
这个连续性条件保证了该平面在每一个方向上都贴合曲面,而不仅仅是在两个切片方向上。下面关于可微性的子节解释了为什么仅有偏导数是不够的。
例 17.7切平面 ✓ 已检验
求曲面 z = 6 − x 2 − 2 y 2 z = 6 - x^2 - 2y^2 z = 6 − x 2 − 2 y 2 在 P ( 1 , 1 , 3 ) P(1, 1, 3) P ( 1 , 1 , 3 ) 处的切平面。
偏导数 f x = − 2 x f_x = -2x f x = − 2 x 和 f y = − 4 y f_y = -4y f y = − 4 y 是多项式,处处连续,并且在 ( 1 , 1 ) (1, 1) ( 1 , 1 ) 处分别为 − 2 -2 − 2 和 − 4 -4 − 4 (第 17.3 节)。切平面为
z = 3 − 2 ( x − 1 ) − 4 ( y − 1 ) , that is, z = 9 − 2 x − 4 y . \begin{aligned} z &= 3 - 2(x - 1) - 4(y - 1), \\ \text{that is,}\quad z &= 9 - 2x - 4y. \end{aligned} z that is, z = 3 − 2 ( x − 1 ) − 4 ( y − 1 ) , = 9 − 2 x − 4 y .
它经过 P : P\mathclose{\text{:}} P : 9 − 2 − 4 = 3 。 9 - 2 - 4 = 3\mathclose{\text{。}} 9 − 2 − 4 = 3 。 曲面位于其下方,因为差值为
( 6 − x 2 − 2 y 2 ) − ( 9 − 2 x − 4 y ) = − ( x − 1 ) 2 − 2 ( y − 1 ) 2 , \begin{aligned} &(6 - x^2 - 2y^2) - (9 - 2x - 4y) \\ &\quad= -(x - 1)^2 - 2(y - 1)^2, \end{aligned} ( 6 − x 2 − 2 y 2 ) − ( 9 − 2 x − 4 y ) = − ( x − 1 ) 2 − 2 ( y − 1 ) 2 ,
该差值在 ( 1 , 1 ) (1, 1) ( 1 , 1 ) 以外的点都是负数。就像凹函数及其切线的图像(模块 8)一样,曲面在它的切平面下方弯曲(图 17.2,右图)。
其图像为切平面的函数,
L ( x , y ) = f ( a , b ) + f x ( a , b ) ( x − a ) + f y ( a , b ) ( y − b ) , \begin{aligned} L(x, y) = f(a, b) &+ f_x(a, b)(x - a) \\ &+ f_y(a, b)(y - b), \end{aligned} L ( x , y ) = f ( a , b ) + f x ( a , b ) ( x − a ) + f y ( a , b ) ( y − b ) ,
是 f f f 在 ( a , b ) (a, b) ( a , b ) 处的线性化 。当 ( x , y ) (x, y) ( x , y ) 接近 ( a , b ) (a, b) ( a , b ) 时,f ( x , y ) ≈ L ( x , y ) f(x, y) \approx L(x, y) f ( x , y ) ≈ L ( x , y ) 是 f f f 在 ( a , b ) (a, b) ( a , b ) 处的线性近似 。用 Δ x = x − a \Delta x = x - a Δ x = x − a 和 Δ y = y − b , \Delta y = y - b\mathclose{\text{,}} Δ y = y − b , 可写成
f ( a + Δ x , b + Δ y ) ≈ f ( a , b ) + f x ( a , b ) Δ x + f y ( a , b ) Δ y : \begin{aligned} f(a + \Delta x, b + \Delta y) &\approx f(a, b) \\ &\quad + f_x(a, b)\,\Delta x \\ &\quad + f_y(a, b)\,\Delta y: \end{aligned} f ( a + Δ x , b + Δ y ) ≈ f ( a , b ) + f x ( a , b ) Δ x + f y ( a , b ) Δ y :
每个变量贡献其自身的速率乘以其自身的改变量。
例 17.8斜边长度的线性近似 ✓ 已检验
一个直角三角形,其直角边分别为 3 和 4,斜边为 5。使用 f ( x , y ) = x 2 + y 2 f(x, y) = \sqrt{x^2 + y^2} f ( x , y ) = x 2 + y 2 在 ( 3 , 4 ) (3, 4) ( 3 , 4 ) 处的线性近似(linearisation)来估计当直角边分别为 3.02 和 3.97 时的斜边长度。
根据链式法则(chain rule),f x = x x 2 + y 2 f_x = \dfrac{x}{\sqrt{x^2 + y^2}} f x = x 2 + y 2 x 和 f y = y x 2 + y 2 f_y = \dfrac{y}{\sqrt{x^2 + y^2}} f y = x 2 + y 2 y 在 ( x , y ) ≠ ( 0 , 0 ) (x, y) \ne (0, 0) ( x , y ) = ( 0 , 0 ) 连续的区域中是连续的。在 ( 3 , 4 ) (3, 4) ( 3 , 4 ) 处,它们分别为 3 5 \tfrac35 5 3 和 4 5 , \tfrac45\mathclose{\text{,}} 5 4 , 因此
L ( x , y ) = 5 + 3 5 ( x − 3 ) + 4 5 ( y − 4 ) . L(x, y) = 5 + \tfrac35(x - 3) + \tfrac45(y - 4). L ( x , y ) = 5 + 5 3 ( x − 3 ) + 5 4 ( y − 4 ) .
用 Δ x = 0.02 \Delta x = 0.02 Δ x = 0.02 和 Δ y = − 0.03 , \Delta y = -0.03\mathclose{\text{,}} Δ y = − 0.03 ,
L ( 3.02 , 3.97 ) = 5 + 0.6 ( 0.02 ) + 0.8 ( − 0.03 ) = 5 + 0.012 − 0.024 = 4.988. \begin{aligned} L(3.02, 3.97) &= 5 + 0.6(0.02) + 0.8(-0.03) \\ &= 5 + 0.012 - 0.024 = 4.988. \end{aligned} L ( 3.02 , 3.97 ) = 5 + 0.6 ( 0.02 ) + 0.8 ( − 0.03 ) = 5 + 0.012 − 0.024 = 4.988.
计算器给出 3.02 2 + 3.97 2 = 24.8813 ≈ 4.98812 : \sqrt{3.02^2 + 3.97^2} = \sqrt{24.8813} \approx 4.98812\mathclose{\text{:}} 3.0 2 2 + 3.9 7 2 = 24.8813 ≈ 4.98812 : 估计值的误差约为 0.00012。
一般情况下,这种近似有多好?从 ( 3 , 4 ) (3, 4) ( 3 , 4 ) 移动到 ( 3 + t , 4 − t ) , (3 + t, 4 - t)\mathclose{\text{,}} ( 3 + t , 4 − t ) , 距离为 2 ∣ t ∣ , \sqrt2\,\abs{t}\mathclose{\text{,}} 2 ∣ t ∣ , 并比较 f f f 与 L : L\mathclose{\text{:}} L :
t t t f f f L L L f − L f - L f − L f − L 2 t \dfrac{f - L}{\sqrt2\,t} 2 t f − L 0.1 0.1 0.1 4.98197 4.98197 4.98197 4.98 4.98 4.98 0.00196748 0.00196748 0.00196748 0.0139122 0.0139122 0.0139122 0.01 0.01 0.01 4.99802 4.99802 4.99802 4.998 4.998 4.998 1.96078 × 10 − 5 1.96078\times10^{-5} 1.96078 × 1 0 − 5 0.00138648 0.00138648 0.00138648 0.001 0.001 0.001 4.99980 4.99980 4.99980 4.9998 4.9998 4.9998 1.96008 × 10 − 7 1.96008\times10^{-7} 1.96008 × 1 0 − 7 0.000138598 0.000138598 0.000138598
如在模块 7 所述,误差 f − L f - L f − L 每次距离缩小十倍时,误差就会缩小约一百倍,因此误差除以距离,在最后一列趋于 0:在 ( 3 , 4 ) (3, 4) ( 3 , 4 ) 附近,误差即使与到 ( 3 , 4 ) (3, 4) ( 3 , 4 ) 的距离相比也很小。这种性质使得平面具有切平面的性质。
可导性
定义 17.7可导性
设函数 f f f 在以 ( a , b ) (a, b) ( a , b ) 为中心的圆盘上有定义。若 f x ( a , b ) 、 f_x(a, b)\mathclose{\text{、}} f x ( a , b ) 、 f y ( a , b ) f_y(a, b) f y ( a , b ) 存在,且其线性化误差 E ( x , y ) = f ( x , y ) − L ( x , y ) E(x, y) = f(x, y) - L(x, y) E ( x , y ) = f ( x , y ) − L ( x , y ) 满足下式,则称它在 ( a , b ) (a, b) ( a , b ) 处可微 :
lim ( x , y ) → ( a , b ) E ( x , y ) ( x − a ) 2 + ( y − b ) 2 = 0. \lim_{(x, y)\to(a, b)}\frac{E(x, y)}{\sqrt{(x - a)^2 + (y - b)^2}} = 0. ( x , y ) → ( a , b ) lim ( x − a ) 2 + ( y − b ) 2 E ( x , y ) = 0.
如果它在一个集合的每一点都可微,就称它在该集合上可微 。
对于一元函数,定理 7.1 已证明,f ′ ( a ) f'(a) f ′ ( a ) 存在时就有 E ( x ) / ( x − a ) → 0 。 E(x)/(x - a) \to 0\mathclose{\text{。}} E ( x ) / ( x − a ) → 0 。 对二元函数,仅有两个偏导数还不够,下文的「深入一步」栏目给出例子。可微要求同一个平面能同时沿所有方向逼近。下面两个定理使定义便于应用,第一个与定理 4.1 类似。
定理 17.4可微函数连续
若 f f f 在 ( a , b ) (a, b) ( a , b ) 可微,则 f f f 在 ( a , b ) (a, b) ( a , b ) 连续。
证明
写 ρ = ( x − a ) 2 + ( y − b ) 2 。 \rho = \sqrt{(x - a)^2 + (y - b)^2}\mathclose{\text{。}} ρ = ( x − a ) 2 + ( y − b ) 2 。 对于 ( x , y ) ≠ ( a , b ) , (x, y) \ne (a, b)\mathclose{\text{,}} ( x , y ) = ( a , b ) ,
f ( x , y ) = L ( x , y ) + E ( x , y ) ρ ρ . f(x, y) = L(x, y) + \frac{E(x, y)}{\rho}\,\rho. f ( x , y ) = L ( x , y ) + ρ E ( x , y ) ρ .
当 ( x , y ) → ( a , b ) : (x, y) \to (a, b)\mathclose{\text{:}} ( x , y ) → ( a , b ) : L ( x , y ) → L ( a , b ) = f ( a , b ) , L(x, y) \to L(a, b) = f(a, b)\mathclose{\text{,}} L ( x , y ) → L ( a , b ) = f ( a , b ) , 因为 L L L 是多项式;E / ρ → 0 , E/\rho \to 0\mathclose{\text{,}} E / ρ → 0 , 由可导性;且 ρ → 0 。 \rho \to 0\mathclose{\text{。}} ρ → 0 。 因此 f ( x , y ) → f ( a , b ) + 0 ⋅ 0 = f ( a , b ) 。 f(x, y) \to f(a, b) + 0 \cdot 0 = f(a, b)\mathclose{\text{。}} f ( x , y ) → f ( a , b ) + 0 ⋅ 0 = f ( a , b ) 。
∎
定理 17.5偏导数连续推出可微
若 f x 、 f_x\mathclose{\text{、}} f x 、 f y f_y f y 在以 ( a , b ) (a, b) ( a , b ) 为中心的圆盘上存在,并且在 ( a , b ) (a, b) ( a , b ) 处连续,则 f f f 在 ( a , b ) (a, b) ( a , b ) 处可微。
证明见下方“深入理解”框中。定理 17.5 是在实践中如何检验可微性的方法。多项式在所有点都可微,且如 e x y sin y e^{xy}\sin y e x y sin y 或 ln ( x 2 + y 2 ) \ln(x^2 + y^2) ln ( x 2 + y 2 ) 这样的函数在其定义域内也均可微:规则给出的偏导数仍是相同类型的公式,并且在该域内连续。切平面的定义(定义 17.6)使用了这个充分条件。更一般地,即使偏导数不连续,可微性本身也能通过相同公式给出切平面。
深入一步偏导数本身是不够的
第一次阅读可以跳过这个框。令 f ( x , y ) = x y x 2 + y 2 f(x, y) = \dfrac{xy}{x^2 + y^2} f ( x , y ) = x 2 + y 2 x y 为 ( x , y ) ≠ ( 0 , 0 ) (x, y) \ne (0, 0) ( x , y ) = ( 0 , 0 ) 和 f ( 0 , 0 ) = 0 , f(0, 0) = 0\mathclose{\text{,}} f ( 0 , 0 ) = 0 , 即例 17.3 中的函数。在两个坐标轴上 f f f 都为 0,因此
f x ( 0 , 0 ) = lim h → 0 f ( h , 0 ) − f ( 0 , 0 ) h = lim h → 0 0 − 0 h = 0 , \begin{aligned} f_x(0, 0) &= \lim_{h\to0}\frac{f(h, 0) - f(0, 0)}{h} \\ &= \lim_{h\to0}\frac{0 - 0}{h} = 0, \end{aligned} f x ( 0 , 0 ) = h → 0 lim h f ( h , 0 ) − f ( 0 , 0 ) = h → 0 lim h 0 − 0 = 0 ,
以及 f y ( 0 , 0 ) = 0 f_y(0, 0) = 0 f y ( 0 , 0 ) = 0 同理。两个偏导数均存在,且原点的线性化是 L ( x , y ) = 0 。 L(x, y) = 0\mathclose{\text{。}} L ( x , y ) = 0 。 但 f f f 在原点不连续(第17.2节),因此由定理17.4可知其在该点不可微,且平面 z = 0 z = 0 z = 0 不是切平面:沿直线 y = x , y = x\mathclose{\text{,}} y = x , 曲面保持在高度 1 2 , \tfrac12\mathclose{\text{,}} 2 1 , 无论多么接近原点。偏导数仅观察沿两个坐标轴的切片,在此处曲面高度为0;而沿其他过原点的直线,其高度则不同。
定理17.5的证明. 设 ( x , y ) ≠ ( a , b ) (x, y) \ne (a, b) ( x , y ) = ( a , b ) 在圆盘内,并写成 Δ x = x − a , \Delta x = x - a\mathclose{\text{,}} Δ x = x − a , Δ y = y − b \Delta y = y - b Δ y = y − b 和 ρ = Δ x 2 + Δ y 2 > 0 . \rho = \sqrt{\Delta x^2 + \Delta y^2} > 0\mathclose{\text{.}} ρ = Δ x 2 + Δ y 2 > 0 . 从 ( a , b ) (a, b) ( a , b ) 到 ( x , y ) (x, y) ( x , y ) 分两步进行,首先改变 y , y\mathclose{\text{,}} y , 然后 x : x\mathclose{\text{:}} x :
f ( x , y ) − f ( a , b ) = [ f ( x , y ) − f ( a , y ) ] + [ f ( a , y ) − f ( a , b ) ] . \begin{aligned} f(x, y) - f(a, b) &= \big[f(x, y) - f(a, y)\big] \\ &\quad + \big[f(a, y) - f(a, b)\big]. \end{aligned} f ( x , y ) − f ( a , b ) = [ f ( x , y ) − f ( a , y ) ] + [ f ( a , y ) − f ( a , b ) ] .
对每一段非零位移,可将 f f f 看作只依赖该变量的函数,应用微分中值定理。两个方括号内的量分别是 f x ( c , y ) Δ x f_x(c, y)\,\Delta x f x ( c , y ) Δ x 和 f y ( a , d ) Δ y , f_y(a, d)\,\Delta y\mathclose{\text{,}} f y ( a , d ) Δ y , 其中 c c c 介于 a a a 和 x x x 之间,d d d 介于 b b b 和 y y y 之间。若 Δ x = 0 , \Delta x = 0\mathclose{\text{,}} Δ x = 0 , 第一个方括号内的量为 0,取 c = a ; c = a\mathclose{\text{;}} c = a ; 若 Δ y = 0 , \Delta y = 0\mathclose{\text{,}} Δ y = 0 , 同理取 d = b 。 d = b\mathclose{\text{。}} d = b 。 两边同减 f x ( a , b ) Δ x + f y ( a , b ) Δ y : f_x(a, b)\,\Delta x + f_y(a, b)\,\Delta y\mathclose{\text{:}} f x ( a , b ) Δ x + f y ( a , b ) Δ y :
E ( x , y ) = [ f x ( c , y ) − f x ( a , b ) ] Δ x + [ f y ( a , d ) − f y ( a , b ) ] Δ y . \begin{aligned} E(x, y) &= \big[f_x(c, y) - f_x(a, b)\big]\Delta x \\ &\quad + \big[f_y(a, d) - f_y(a, b)\big]\Delta y. \end{aligned} E ( x , y ) = [ f x ( c , y ) − f x ( a , b ) ] Δ x + [ f y ( a , d ) − f y ( a , b ) ] Δ y .
由于 ∣ Δ x ∣ ≤ ρ \abs{\Delta x} \le \rho ∣ Δ x ∣ ≤ ρ 和 ∣ Δ y ∣ ≤ ρ , \abs{\Delta y} \le \rho\mathclose{\text{,}} ∣ Δ y ∣ ≤ ρ ,
∣ E ( x , y ) ∣ ρ ≤ ∣ f x ( c , y ) − f x ( a , b ) ∣ + ∣ f y ( a , d ) − f y ( a , b ) ∣ . \begin{aligned} \frac{\abs{E(x, y)}}{\rho} &\le \abs{f_x(c, y) - f_x(a, b)} \\ &\quad + \abs{f_y(a, d) - f_y(a, b)}. \end{aligned} ρ ∣ E ( x , y ) ∣ ≤ ∣ f x ( c , y ) − f x ( a , b ) ∣ + ∣ f y ( a , d ) − f y ( a , b ) ∣ .
当 ( x , y ) → ( a , b ) (x, y) \to (a, b) ( x , y ) → ( a , b ) 时,点 ( c , y ) (c, y) ( c , y ) 和 ( a , d ) (a, d) ( a , d ) 也趋近于 ( a , b ) , (a, b)\mathclose{\text{,}} ( a , b ) , 因此由 f x f_x f x 和 f y f_y f y 在 ( a , b ) (a, b) ( a , b ) 处的连续性可知右边趋于 0。同样, ∣ E ∣ / ρ \abs{E}/\rho ∣ E ∣ / ρ 也趋于 0: f f f 在 ( a , b ) (a, b) ( a , b ) 处可导。
总微分
第7.2节 有一个适用于多个变量的版本。
定义 17.8总微分
设 z = f ( x , y ) z = f(x, y) z = f ( x , y ) 可微,并取微分 d x dx d x 和 d y dy d y 为独立变量。z z z 的全微分 为
d z = f x ( x , y ) d x + f y ( x , y ) d y = ∂ z ∂ x d x + ∂ z ∂ y d y . dz = f_x(x, y)\,dx + f_y(x, y)\,dy = \frac{\partial z}{\partial x}\,dx + \frac{\partial z}{\partial y}\,dy. d z = f x ( x , y ) d x + f y ( x , y ) d y = ∂ x ∂ z d x + ∂ y ∂ z d y .
当x x x 和y y y 分别变化d x dx d x 和d y dy d y 时,z z z 的实际变化为Δ z = f ( x + d x , y + d y ) − f ( x , y ) , \Delta z = f(x + dx, y + dy) - f(x, y)\mathclose{\text{,}} Δ z = f ( x + d x , y + d y ) − f ( x , y ) , 而d z dz d z 是线性化的变化;当d x dx d x 和d y dy d y 较小时,Δ z ≈ d z \Delta z \approx dz Δ z ≈ d z 成立。如[小节 7.3 所述,这会传播测量误差,且现在来自多个测量值。
例 17.9一个圆柱体的测量误差 ✓ 已检验
一个圆柱体的半径和高度分别测量为 r = 3 r = 3 r = 3 厘米和 h = 10 h = 10 h = 10 厘米,其中半径 r r r 的绝对误差不超过 0.02 厘米,高度 h h h 的绝对误差不超过 0.05 厘米。估计计算出的体积 V = π r 2 h V = \pi r^2 h V = π r 2 h 的最大可能绝对误差和相对误差。
在 d V = V r d r + V h d h = 2 π r h d r + π r 2 d h dV = V_r\,dr + V_h\,dh = 2\pi rh\,dr + \pi r^2\,dh d V = V r d r + V h d h = 2 π r h d r + π r 2 d h 处,以及在 ( 3 , 10 ) (3, 10) ( 3 , 10 ) 处, V r = 60 π V_r = 60\pi V r = 60 π 和 V h = 9 π 。 V_h = 9\pi\mathclose{\text{。}} V h = 9 π 。 设 d r dr d r 和 d h dh d h 为真实值减去测量值,因此 d V dV d V 估计误差,并遵循模块 7 中的符号约定。当两个项符号相同时,误差的绝对值 ∣ d V ∣ \abs{dV} ∣ d V ∣ 最大,且每个测量误差都达到允许的最大值:
∣ d V ∣ ≤ 60 π ( 0.02 ) + 9 π ( 0.05 ) = 1.2 π + 0.45 π = 1.65 π ≈ 5.18 cm 3 . \begin{aligned} \abs{dV} &\le 60\pi(0.02) + 9\pi(0.05) \\ &= 1.2\pi + 0.45\pi = 1.65\pi \approx 5.18 \text{ cm}^3. \end{aligned} ∣ d V ∣ ≤ 60 π ( 0.02 ) + 9 π ( 0.05 ) = 1.2 π + 0.45 π = 1.65 π ≈ 5.18 cm 3 .
所以计算出的体积,90 π ≈ 282.7 90\pi \approx 282.7 90 π ≈ 282.7 cm³,可能误差约为 5.2 cm³。这是从切平面得到的估计,不是对精确体积误差的界限。将 d V dV d V 除以测得的体积 V = π r 2 h V = \pi r^2 h V = π r 2 h 得到
d V V = 2 π r h d r + π r 2 d h π r 2 h = 2 d r r + d h h , \begin{aligned} \frac{dV}{V} &= \frac{2\pi rh\,dr + \pi r^2\,dh}{\pi r^2 h} \\ &= 2\,\frac{dr}{r} + \frac{dh}{h}, \end{aligned} V d V = π r 2 h 2 π r h d r + π r 2 d h = 2 r d r + h d h ,
相对误差估计为 ∣ d V ∣ / V 。 \abs{dV}/V\mathclose{\text{。}} ∣ d V ∣ / V 。 这里这个估计最多为 2 ⋅ 0.02 3 + 0.05 10 ≈ 0.0133 + 0.005 = 0.0183 , 2 \cdot \tfrac{0.02}{3} + \tfrac{0.05}{10} \approx 0.0133 + 0.005 = 0.0183\mathclose{\text{,}} 2 ⋅ 3 0.02 + 10 0.05 ≈ 0.0133 + 0.005 = 0.0183 , 约为 1.8%。在这个估计中,半径的相对误差计算了两次,因为半径是平方出现的。
注意
d z dz d z 不等于 Δ z : \Delta z\mathclose{\text{:}} Δ z : d z dz d z 是切平面方向的变化,Δ z \Delta z Δ z 是曲面上方向的变化。可微性使得对于足够小的变化,近似是准确的。为了估计最大的绝对误差,将各项的大小相加,∣ f x ∣ ∣ d x ∣ + ∣ f y ∣ ∣ d y ∣ : \abs{f_x}\abs{dx} + \abs{f_y}\abs{dy}\mathclose{\text{:}} ∣ f x ∣ ∣ d x ∣ + ∣ f y ∣ ∣ d y ∣ : 两个测量中的误差可能以相同方向影响结果。这限制了微分;一个精确的误差界限需要对剩余项进行控制。
在单变量情形下,速率相乘(小节 5.5 )。当z z z 依赖于x x x 和y , y\mathclose{\text{,}} y , 且两者均依赖于时间t t t 时,t t t 的变化通过两条路径影响z , z\mathclose{\text{,}} z , 即经由x x x 和经由y , y\mathclose{\text{,}} y , 且这两部分贡献相加。
定理 17.6链式法则
假设 x = x ( t ) x = x(t) x = x ( t ) 和 y = y ( t ) y = y(t) y = y ( t ) 在 t 0 t_0 t 0 处可导,且 z = f ( x , y ) z = f(x, y) z = f ( x , y ) 在 ( x ( t 0 ) , y ( t 0 ) ) \big(x(t_0), y(t_0)\big) ( x ( t 0 ) , y ( t 0 ) ) 处可导。那么 z = f ( x ( t ) , y ( t ) ) z = f\big(x(t), y(t)\big) z = f ( x ( t ) , y ( t ) ) 在 t 0 t_0 t 0 处可导,并
d z d t = ∂ z ∂ x d x d t + ∂ z ∂ y d y d t , \frac{dz}{dt} = \frac{\partial z}{\partial x}\,\frac{dx}{dt} + \frac{\partial z}{\partial y}\,\frac{dy}{dt}, d t d z = ∂ x ∂ z d t d x + ∂ y ∂ z d t d y ,
且偏导数在 ( x ( t 0 ) , y ( t 0 ) ) \big(x(t_0), y(t_0)\big) ( x ( t 0 ) , y ( t 0 ) ) 处取,其余导数在 t 0 t_0 t 0 处取。
证明
设 Δ t ≠ 0 , \Delta t \ne 0\mathclose{\text{,}} Δ t = 0 , 并设 Δ x 、 \Delta x\mathclose{\text{、}} Δ x 、 Δ y \Delta y Δ y 和 Δ z \Delta z Δ z 分别为 x 、 x\mathclose{\text{、}} x 、 y y y 和 z z z 在 t t t 从 t 0 t_0 t 0 变化到 t 0 + Δ t t_0 + \Delta t t 0 + Δ t 时的改变量。写出 ρ = Δ x 2 + Δ y 2 。 \rho = \sqrt{\Delta x^2 + \Delta y^2}\mathclose{\text{。}} ρ = Δ x 2 + Δ y 2 。 根据可微性的定义,
Δ z = f x Δ x + f y Δ y + E , \Delta z = f_x\,\Delta x + f_y\,\Delta y + E, Δ z = f x Δ x + f y Δ y + E ,
其中 E / ρ → 0 E/\rho \to 0 E / ρ → 0 作为 ( Δ x , Δ y ) → ( 0 , 0 ) 。 (\Delta x, \Delta y) \to (0, 0)\mathclose{\text{。}} ( Δ x , Δ y ) → ( 0 , 0 ) 。 令 ε = E / ρ \varepsilon = E/\rho ε = E / ρ 当 ρ ≠ 0 \rho \ne 0 ρ = 0 且 ε = 0 \varepsilon = 0 ε = 0 当 ρ = 0 。 \rho = 0\mathclose{\text{。}} ρ = 0 。 那么 E = ε ρ E = \varepsilon\rho E = ερ 在两种情况下:如果 ρ = 0 , \rho = 0\mathclose{\text{,}} ρ = 0 , 则 x x x 和 y y y 不变,因此 z z z 也不变,且 E = 0 。 E = 0\mathclose{\text{。}} E = 0 。 两边除以 Δ t : \Delta t\mathclose{\text{:}} Δ t :
Δ z Δ t = f x Δ x Δ t + f y Δ y Δ t + ε ρ Δ t . \frac{\Delta z}{\Delta t} = f_x\,\frac{\Delta x}{\Delta t} + f_y\,\frac{\Delta y}{\Delta t} + \varepsilon\,\frac{\rho}{\Delta t}. Δ t Δ z = f x Δ t Δ x + f y Δ t Δ y + ε Δ t ρ .
设 Δ t → 0 。 \Delta t \to 0\mathclose{\text{。}} Δ t → 0 。 商 Δ x / Δ t \Delta x/\Delta t Δ x /Δ t 和 Δ y / Δ t \Delta y/\Delta t Δ y /Δ t 趋于 d x / d t dx/dt d x / d t 和 d y / d t 。 dy/dt\mathclose{\text{。}} d y / d t 。 变化量 Δ x \Delta x Δ x 和 Δ y \Delta y Δ y 趋于 0,因为可导函数是连续的,所以 ε → 0 ; \varepsilon \to 0\mathclose{\text{;}} ε → 0 ; 且 ∣ ρ / Δ t ∣ = ( Δ x / Δ t ) 2 + ( Δ y / Δ t ) 2 \abs{\rho/\Delta t} = \sqrt{(\Delta x/\Delta t)^2 + (\Delta y/\Delta t)^2} ∣ ρ /Δ t ∣ = ( Δ x /Δ t ) 2 + ( Δ y /Δ t ) 2 有界,因为它趋于 ( d x / d t ) 2 + ( d y / d t ) 2 。 \sqrt{(dx/dt)^2 + (dy/dt)^2}\mathclose{\text{。}} ( d x / d t ) 2 + ( d y / d t ) 2 。 因此最后一项趋于 0,且 Δ z / Δ t \Delta z/\Delta t Δ z /Δ t 趋于 f x d x d t + f y d y d t 。 f_x\,\dfrac{dx}{dt} + f_y\,\dfrac{dy}{dt}\mathclose{\text{。}} f x d t d x + f y d t d y 。
∎
例 17.10变化的圆柱体 ✓ 已检验
圆柱体的半径以 0.1 cm/s 的速度增长,而高度以 0.3 cm/s 的速度减少。当半径为 r = 3 r = 3 r = 3 cm,高度为 h = 10 h = 10 h = 10 cm 时,体积是增大还是减小?变化率是多少?
根据定理 17.6,
d V d t = ∂ V ∂ r d r d t + ∂ V ∂ h d h d t = 2 π r h d r d t + π r 2 d h d t . \begin{aligned} \frac{dV}{dt} &= \frac{\partial V}{\partial r}\,\frac{dr}{dt} + \frac{\partial V}{\partial h}\,\frac{dh}{dt} \\ &= 2\pi rh\,\frac{dr}{dt} + \pi r^2\,\frac{dh}{dt}. \end{aligned} d t d V = ∂ r ∂ V d t d r + ∂ h ∂ V d t d h = 2 π r h d t d r + π r 2 d t d h .
在这个时刻 ∂ V / ∂ r = 60 π , \partial V/\partial r = 60\pi\mathclose{\text{,}} ∂ V / ∂ r = 60 π , ∂ V / ∂ h = 9 π , \partial V/\partial h = 9\pi\mathclose{\text{,}} ∂ V / ∂ h = 9 π , d r / d t = 0.1 dr/dt = 0.1 d r / d t = 0.1 和 d h / d t = − 0.3 , dh/dt = -0.3\mathclose{\text{,}} d h / d t = − 0.3 , 因此
d V d t = 60 π ( 0.1 ) + 9 π ( − 0.3 ) = 6 π − 2.7 π = 3.3 π ≈ 10.37 cm 3 / s . \begin{aligned} \frac{dV}{dt} &= 60\pi(0.1) + 9\pi(-0.3) = 6\pi - 2.7\pi \\ &= 3.3\pi \approx 10.37 \text{ cm}^3/\text{s}. \end{aligned} d t d V = 60 π ( 0.1 ) + 9 π ( − 0.3 ) = 6 π − 2.7 π = 3.3 π ≈ 10.37 cm 3 / s .
体积在增大。高度减少的速度是半径增长速度的三倍,但体积对半径的变化更为敏感,超过六倍。
树状图
用更多变量时,一个 树图 可以追踪路线(图 17.3)。将依赖变量放在顶部,中间变量放在其下方,独立变量放在底部,并将每个变量连接到它直接依赖的变量上。用上层变量对下层变量的导数标记每条分支。
要点
顶部变量对底部变量的导数等于从顶部到该变量的所有路径上的标签乘积之和。
图 17.3 链式法则的树状图。左图:z = f ( x , y ) , z = f(x, y)\mathclose{\text{,}} z = f ( x , y ) , 其中x x x 和y y y 是t t t 的函数;从z z z 到t t t 的两条路径对应定理17.6中的两项。右图:x x x 和y y y 是s s s 和t t t 的函数;从z z z 到s s s 的两条彩色路径给出∂ z / ∂ s , \partial z/\partial s\mathclose{\text{,}} ∂ z / ∂ s , 而到t t t 的两条路径以相同方式给出∂ z / ∂ t 。 \partial z/\partial t\mathclose{\text{。}} ∂ z / ∂ t 。
当 x x x 和 y y y 依赖于两个变量 s s s 和 t , t\mathclose{\text{,}} t , 保持 t t t 固定:那么 x x x 和 y y y 是 s s s 的函数,且定理 17.6 适用,其中 s s s 代替 t 。 t\mathclose{\text{。}} t 。 对 s s s 的导数,当 t t t 固定时为偏导数,因此:
定理 17.7两个参数的链式法则
假设 x = x ( s , t ) x = x(s, t) x = x ( s , t ) 和 y = y ( s , t ) y = y(s, t) y = y ( s , t ) 在 ( s , t ) (s, t) ( s , t ) 处有偏导数,且 z = f ( x , y ) z = f(x, y) z = f ( x , y ) 在 ( x ( s , t ) , y ( s , t ) ) \big(x(s, t), y(s, t)\big) ( x ( s , t ) , y ( s , t ) ) 处可导。那么
∂ z ∂ s = ∂ z ∂ x ∂ x ∂ s + ∂ z ∂ y ∂ y ∂ s , ∂ z ∂ t = ∂ z ∂ x ∂ x ∂ t + ∂ z ∂ y ∂ y ∂ t . \begin{aligned} \frac{\partial z}{\partial s} &= \frac{\partial z}{\partial x}\,\frac{\partial x}{\partial s} + \frac{\partial z}{\partial y}\,\frac{\partial y}{\partial s}, \\ \frac{\partial z}{\partial t} &= \frac{\partial z}{\partial x}\,\frac{\partial x}{\partial t} + \frac{\partial z}{\partial y}\,\frac{\partial y}{\partial t}. \end{aligned} ∂ s ∂ z ∂ t ∂ z = ∂ x ∂ z ∂ s ∂ x + ∂ y ∂ z ∂ s ∂ y , = ∂ x ∂ z ∂ t ∂ x + ∂ y ∂ z ∂ t ∂ y .
相同的证明,包含更多项,给出关键思想的一般规则。可导性对于 n n n 变量的定义与两个变量的情形相同,只是距离在 n n n 维度中;如果 u u u 是 x 1 , … , x n x_1, \dots, x_n x 1 , … , x n 的可导函数,而每个变量对 t 1 , … , t m t_1, \dots, t_m t 1 , … , t m 都有偏导数,那么对于每个 i i i
∂ u ∂ t i = ∂ u ∂ x 1 ∂ x 1 ∂ t i + ∂ u ∂ x 2 ∂ x 2 ∂ t i + ⋯ + ∂ u ∂ x n ∂ x n ∂ t i . \frac{\partial u}{\partial t_i} = \frac{\partial u}{\partial x_1}\frac{\partial x_1}{\partial t_i} + \frac{\partial u}{\partial x_2}\frac{\partial x_2}{\partial t_i} + \dots + \frac{\partial u}{\partial x_n}\frac{\partial x_n}{\partial t_i}. ∂ t i ∂ u = ∂ x 1 ∂ u ∂ t i ∂ x 1 + ∂ x 2 ∂ u ∂ t i ∂ x 2 + ⋯ + ∂ x n ∂ u ∂ t i ∂ x n .
例 17.11极坐标 ✓ 已检验
设 z = x 2 y , z = x^2y\mathclose{\text{,}} z = x 2 y , 其中 x = r cos θ x = r\cos\theta x = r cos θ 和 y = r sin θ y = r\sin\theta y = r sin θ 由极坐标给出(模块 16)。求 ∂ z / ∂ r \partial z/\partial r ∂ z / ∂ r 和 ∂ z / ∂ θ \partial z/\partial\theta ∂ z / ∂ θ 在 r = 2 , r = 2\mathclose{\text{,}} r = 2 , θ = π / 6 \theta = \pi/6 θ = π /6 处的值,并通过代入进行验证。
树是图17.3中的右树,其中 r r r 和 θ \theta θ 代替 s s s 和 t 。 t\mathclose{\text{。}} t 。 标签为 z x = 2 x y , z_x = 2xy\mathclose{\text{,}} z x = 2 x y , z y = x 2 , z_y = x^2\mathclose{\text{,}} z y = x 2 , x r = cos θ , x_r = \cos\theta\mathclose{\text{,}} x r = cos θ , y r = sin θ , y_r = \sin\theta\mathclose{\text{,}} y r = sin θ , x θ = − r sin θ x_\theta = -r\sin\theta x θ = − r sin θ 和 y θ = r cos θ , y_\theta = r\cos\theta\mathclose{\text{,}} y θ = r cos θ , 因此
∂ z ∂ r = 2 x y cos θ + x 2 sin θ , ∂ z ∂ θ = − 2 x y r sin θ + x 2 r cos θ . \begin{aligned} \frac{\partial z}{\partial r} &= 2xy\cos\theta + x^2\sin\theta, \\ \frac{\partial z}{\partial \theta} &= -2xy\,r\sin\theta + x^2\,r\cos\theta. \end{aligned} ∂ r ∂ z ∂ θ ∂ z = 2 x y cos θ + x 2 sin θ , = − 2 x y r sin θ + x 2 r cos θ .
在 r = 2 r = 2 r = 2 和 θ = π / 6 \theta = \pi/6 θ = π /6 处, x = 2 cos π 6 = 3 x = 2\cos\frac{\pi}{6} = \sqrt3 x = 2 cos 6 π = 3 和 y = 2 sin π 6 = 1 , y = 2\sin\frac{\pi}{6} = 1\mathclose{\text{,}} y = 2 sin 6 π = 1 , 因此
∂ z ∂ r = 2 3 ⋅ 3 2 + 3 ⋅ 1 2 = 3 + 3 2 = 9 2 , ∂ z ∂ θ = − 2 3 ⋅ 2 ⋅ 1 2 + 3 ⋅ 2 ⋅ 3 2 = − 2 3 + 3 3 = 3 . \begin{aligned} \frac{\partial z}{\partial r} &= 2\sqrt3\cdot\frac{\sqrt3}{2} + 3\cdot\frac12 = 3 + \frac32 = \frac92, \\ \frac{\partial z}{\partial \theta} &= -2\sqrt3\cdot 2\cdot\frac12 + 3\cdot 2\cdot\frac{\sqrt3}{2} \\ &= -2\sqrt3 + 3\sqrt3 = \sqrt3. \end{aligned} ∂ r ∂ z ∂ θ ∂ z = 2 3 ⋅ 2 3 + 3 ⋅ 2 1 = 3 + 2 3 = 2 9 , = − 2 3 ⋅ 2 ⋅ 2 1 + 3 ⋅ 2 ⋅ 2 3 = − 2 3 + 3 3 = 3 .
检查:先代入, z = r 3 cos 2 θ sin θ , z = r^3\cos^2\theta\sin\theta\mathclose{\text{,}} z = r 3 cos 2 θ sin θ , 因此 ∂ z / ∂ r = 3 r 2 cos 2 θ sin θ = 3 ⋅ 4 ⋅ 3 4 ⋅ 1 2 = 9 2 。 \partial z/\partial r = 3r^2\cos^2\theta\sin\theta = 3 \cdot 4 \cdot \tfrac34 \cdot \tfrac12 = \tfrac92\mathclose{\text{。}} ∂ z / ∂ r = 3 r 2 cos 2 θ sin θ = 3 ⋅ 4 ⋅ 4 3 ⋅ 2 1 = 2 9 。 同时 ∂ z / ∂ θ = r 3 cos θ ( cos 2 θ − 2 sin 2 θ ) , \partial z/\partial\theta = r^3\cos\theta(\cos^2\theta - 2\sin^2\theta)\mathclose{\text{,}} ∂ z / ∂ θ = r 3 cos θ ( cos 2 θ − 2 sin 2 θ ) , 在该点为 8 ⋅ 3 2 ( 3 4 − 1 2 ) = 3 。 8\cdot\tfrac{\sqrt3}{2}(\tfrac34 - \tfrac12) = \sqrt3\mathclose{\text{。}} 8 ⋅ 2 3 ( 4 3 − 2 1 ) = 3 。 链式法则不需要这样的代入,对于复杂的 f f f 可能不切实际。
注意
每条路径都起作用。常见的错误是写出 ∂ z ∂ s = ∂ z ∂ x ∂ x ∂ s , \dfrac{\partial z}{\partial s} = \dfrac{\partial z}{\partial x}\dfrac{\partial x}{\partial s}\mathclose{\text{,}} ∂ s ∂ z = ∂ x ∂ z ∂ s ∂ x , 仿佛 ∂ x \partial x ∂ x 消去了,而忘记通过 y y y 的路径。偏导数不是分数,当有两个中间变量时,链式法则有两个项。
隐函数求导
小节 6.4 ] 找到曲线如圆 x 2 + y 2 = 25 x^2 + y^2 = 25 x 2 + y 2 = 25 的切线斜率,通过对其方程进行求导。链式法则解释了该方法并将其转化为公式。将曲线写成 F ( x , y ) = 0 , F(x, y) = 0\mathclose{\text{,}} F ( x , y ) = 0 , 其中 F F F 在所讨论的点附近可导,且假设在该点附近曲线是某个可导函数 y = y ( x ) y = y(x) y = y ( x ) 的图像。则 F ( x , y ( x ) ) = 0 F\big(x, y(x)\big) = 0 F ( x , y ( x ) ) = 0 对所有 x x x 附近的点成立。根据定理 17.6 对 x x x 求导,其中 x x x 本身作为第一个中间变量(d x / d x = 1 ): dx/dx = 1\mathclose{\text{):}} d x / d x = 1 ):
F x + F y d y d x = 0 , so d y d x = − F x F y ( F y ≠ 0 ) . F_x + F_y\,\frac{dy}{dx} = 0, \quad\text{so}\quad \frac{dy}{dx} = -\frac{F_x}{F_y} \quad (F_y \ne 0). F x + F y d x d y = 0 , so d x d y = − F y F x ( F y = 0 ) .
模块 6 承诺了一个定理,当 d y / d x dy/dx d y / d x 的系数,此处为 F y , F_y\mathclose{\text{,}} F y , 不为 0 时,该定理保证函数 y ( x ) y(x) y ( x ) 可导:
定理 17.8隐函数定理
设 F F F 在以 ( a , b ) (a, b) ( a , b ) 为中心的圆盘上有连续偏导数,且 F ( a , b ) = 0 、 F(a, b) = 0\mathclose{\text{、}} F ( a , b ) = 0 、 F y ( a , b ) ≠ 0 。 F_y(a, b) \ne 0\mathclose{\text{。}} F y ( a , b ) = 0 。 则在 ( a , b ) (a, b) ( a , b ) 附近,曲线 F ( x , y ) = 0 F(x, y) = 0 F ( x , y ) = 0 上的点构成一个可微函数 y = y ( x ) y = y(x) y = y ( x ) 的图像。该函数定义在含 a a a 的开区间上,且 y ( a ) = b , y(a) = b\mathclose{\text{,}} y ( a ) = b , 并满足
d y d x = − F x ( x , y ) F y ( x , y ) . \frac{dy}{dx} = -\frac{F_x(x, y)}{F_y(x, y)}. d x d y = − F y ( x , y ) F x ( x , y ) .
其证明属于分析课程的内容;本系列使用该定理而不予证明。
例 17.12笛卡尔叶线再次出现 ✓ 已检验
找出 d y / d x dy/dx d y / d x 在叶线 x 3 + y 3 = 6 x y x^3 + y^3 = 6xy x 3 + y 3 = 6 x y 上的 例 6.5 的公式],并求出 ( 3 , 3 ) (3, 3) ( 3 , 3 ) 处的斜率。
将曲线写成 F ( x , y ) = x 3 + y 3 − 6 x y = 0 。 F(x, y) = x^3 + y^3 - 6xy = 0\mathclose{\text{。}} F ( x , y ) = x 3 + y 3 − 6 x y = 0 。 然后 F x = 3 x 2 − 6 y F_x = 3x^2 - 6y F x = 3 x 2 − 6 y 和 F y = 3 y 2 − 6 x , F_y = 3y^2 - 6x\mathclose{\text{,}} F y = 3 y 2 − 6 x , 因此在 y 2 ≠ 2 x , y^2 \ne 2x\mathclose{\text{,}} y 2 = 2 x ,
d y d x = − 3 x 2 − 6 y 3 y 2 − 6 x = 2 y − x 2 y 2 − 2 x , \frac{dy}{dx} = -\frac{3x^2 - 6y}{3y^2 - 6x} = \frac{2y - x^2}{y^2 - 2x}, d x d y = − 3 y 2 − 6 x 3 x 2 − 6 y = y 2 − 2 x 2 y − x 2 ,
例 6.5 的答案。在 ( 3 , 3 ) , (3, 3)\mathclose{\text{,}} ( 3 , 3 ) , F y = 27 − 18 = 9 ≠ 0 , F_y = 27 - 18 = 9 \ne 0\mathclose{\text{,}} F y = 27 − 18 = 9 = 0 , 斜率是 6 − 9 9 − 6 = − 1 。 \dfrac{6 - 9}{9 - 6} = -1\mathclose{\text{。}} 9 − 6 6 − 9 = − 1 。 在原点 F x = F y = 0 : F_x = F_y = 0\mathclose{\text{:}} F x = F y = 0 : 隐函数定理在那里无能为力,事实上曲线在此处交叉。
同样地,如果 F F F 在 F ( x , y , z ) = 0 F(x, y, z) = 0 F ( x , y , z ) = 0 上某点附近具有连续偏导数,并且 F z ≠ 0 F_z \ne 0 F z = 0 在该点处存在,则方程定义 z z z 为 x x x 和 y y y 在该点附近的可微函数(定理有一个三变量版本)。固定 y y y 并对 F ( x , y , z ( x , y ) ) = 0 F\big(x, y, z(x, y)\big) = 0 F ( x , y , z ( x , y ) ) = 0 关于 x x x 求导得到 F x + F z ∂ z ∂ x = 0 , F_x + F_z\,\dfrac{\partial z}{\partial x} = 0\mathclose{\text{,}} F x + F z ∂ x ∂ z = 0 , 对 y y y 同样如此:
∂ z ∂ x = − F x F z , ∂ z ∂ y = − F y F z . \frac{\partial z}{\partial x} = -\frac{F_x}{F_z}, \qquad \frac{\partial z}{\partial y} = -\frac{F_y}{F_z}. ∂ x ∂ z = − F z F x , ∂ y ∂ z = − F z F y .
例 17.14 使用了这些公式。
站在山脊上。地面的陡峭程度取决于你面对的方向:直上山坡时最陡,沿山坡则平坦。偏导数 f x f_x f x 和 f y f_y f y 只能给出东、北两个方向上的坡度。本节将找出所有方向上的坡度,并确定最陡的方向。
定义 17.9方向导数
设 u = ⟨ u 1 , u 2 ⟩ \vb{u} = \langle u_1, u_2\rangle u = ⟨ u 1 , u 2 ⟩ 为一个单位向量。函数 f f f 在点 ( a , b ) (a, b) ( a , b ) 沿 u \vb{u} u 方向的 方向导数 是
D u f ( a , b ) = lim h → 0 f ( a + h u 1 , b + h u 2 ) − f ( a , b ) h , D_{\vb{u}} f(a, b) = \lim_{h\to0}\frac{f(a + hu_1, b + hu_2) - f(a, b)}{h}, D u f ( a , b ) = h → 0 lim h f ( a + h u 1 , b + h u 2 ) − f ( a , b ) ,
当该极限存在时成立。
D u f D_{\vb{u}} f D u f 读作“f在u处的子D”。点( a + h u 1 , b + h u 2 ) (a + hu_1, b + hu_2) ( a + h u 1 , b + h u 2 ) 位于通过( a , b ) (a, b) ( a , b ) 且方向为u \vb{u} u 的直线上,距离( a , b ) (a, b) ( a , b ) 为∣ h ∣ , \abs{h}\mathclose{\text{,}} ∣ h ∣ , 因为∥ u ∥ = 1 ; \norm{\vb{u}} = 1\mathclose{\text{;}} ∥ u ∥ = 1 ; 因此D u f ( a , b ) D_{\vb{u}} f(a, b) D u f ( a , b ) 表示从( a , b ) (a, b) ( a , b ) 沿该方向移动时,f f f 每单位距离的变化率。对于u = i = ⟨ 1 , 0 ⟩ , \vb{u} = \vb{i} = \langle 1, 0\rangle\mathclose{\text{,}} u = i = ⟨ 1 , 0 ⟩ , 其值为f x ( a , b ) , f_x(a, b)\mathclose{\text{,}} f x ( a , b ) , 对于u = j = ⟨ 0 , 1 ⟩ , \vb{u} = \vb{j} = \langle 0, 1\rangle\mathclose{\text{,}} u = j = ⟨ 0 , 1 ⟩ , 其值为f y ( a , b ) 。 f_y(a, b)\mathclose{\text{。}} f y ( a , b ) 。
定义 17.10梯度
假设其偏导数存在,函数 f f f 在点 ( a , b ) (a, b) ( a , b ) 处的 梯度 是向量
∇ f ( a , b ) = ⟨ f x ( a , b ) , f y ( a , b ) ⟩ . \nabla f(a, b) = \big\langle f_x(a, b), f_y(a, b)\big\rangle. ∇ f ( a , b ) = ⟨ f x ( a , b ) , f y ( a , b ) ⟩ .
对于一个三变量函数, ∇ f = ⟨ f x , f y , f z ⟩ 。 \nabla f = \langle f_x, f_y, f_z\rangle\mathclose{\text{。}} ∇ f = ⟨ f x , f y , f z ⟩ 。
符号 ∇ \nabla ∇ 称为“nabla”,而 ∇ f \nabla f ∇ f 读作“del f”或“grad f”。一个二变量函数的梯度是一个在其定义域平面内的向量;当非零时,它在等值线图上给出一个方向。如果 f f f 在 ( a , b ) (a, b) ( a , b ) 处可微,则第17.4节中的线性近似为 f ( a + Δ x , b + Δ y ) ≈ f ( a , b ) + ∇ f ( a , b ) ⋅ ⟨ Δ x , Δ y ⟩ , f(a + \Delta x, b + \Delta y) \approx f(a, b) + \nabla f(a, b)\cdot\langle\Delta x, \Delta y\rangle\mathclose{\text{,}} f ( a + Δ x , b + Δ y ) ≈ f ( a , b ) + ∇ f ( a , b ) ⋅ ⟨ Δ x , Δ y ⟩ , 其中模块16中的点积适用。方向导数来源于梯度的相同方式。
定理 17.9用梯度计算方向导数
若 f f f 在 ( a , b ) (a, b) ( a , b ) 处可微,则 f f f 在 ( a , b ) (a, b) ( a , b ) 处沿任意单位向量 u = ⟨ u 1 , u 2 ⟩ \vb{u} = \langle u_1, u_2\rangle u = ⟨ u 1 , u 2 ⟩ 的方向导数都存在,且
D u f ( a , b ) = ∇ f ( a , b ) ⋅ u = f x ( a , b ) u 1 + f y ( a , b ) u 2 . \begin{aligned} D_{\vb{u}} f(a, b) &= \nabla f(a, b)\cdot\vb{u} \\ &= f_x(a, b)\,u_1 + f_y(a, b)\,u_2. \end{aligned} D u f ( a , b ) = ∇ f ( a , b ) ⋅ u = f x ( a , b ) u 1 + f y ( a , b ) u 2 .
证明
设 g ( h ) = f ( a + h u 1 , b + h u 2 ) 。 g(h) = f(a + hu_1, b + hu_2)\mathclose{\text{。}} g ( h ) = f ( a + h u 1 , b + h u 2 ) 。 定义 D u f ( a , b ) D_{\vb{u}} f(a, b) D u f ( a , b ) 的极限为 lim h → 0 g ( h ) − g ( 0 ) h = g ′ ( 0 ) 。 \lim_{h\to0}\dfrac{g(h) - g(0)}{h} = g'(0)\mathclose{\text{。}} lim h → 0 h g ( h ) − g ( 0 ) = g ′ ( 0 ) 。 此处 g g g 是 f f f 与 x ( h ) = a + h u 1 x(h) = a + hu_1 x ( h ) = a + h u 1 和 y ( h ) = b + h u 2 y(h) = b + hu_2 y ( h ) = b + h u 2 的复合,其导数为 u 1 u_1 u 1 和 u 2 。 u_2\mathclose{\text{。}} u 2 。 根据链式法则(定理17.6), g ′ ( 0 ) g'(0) g ′ ( 0 ) 存在且
g ′ ( 0 ) = f x ( a , b ) u 1 + f y ( a , b ) u 2 = ∇ f ( a , b ) ⋅ u . \begin{aligned} g'(0) &= f_x(a, b)\,u_1 + f_y(a, b)\,u_2 \\ &= \nabla f(a, b)\cdot\vb{u}. \end{aligned} g ′ ( 0 ) = f x ( a , b ) u 1 + f y ( a , b ) u 2 = ∇ f ( a , b ) ⋅ u .
∎
例 17.13一个方向导数 ✓ 已检验
设 f ( x , y ) = x e y 。 f(x, y) = xe^y\mathclose{\text{。}} f ( x , y ) = x e y 。 求 f f f 在 ( 2 , 0 ) (2, 0) ( 2 , 0 ) 处沿点 ( 5 , 4 ) (5, 4) ( 5 , 4 ) 方向的变化率。
f x = e y f_x = e^y f x = e y 和 f y = x e y f_y = xe^y f y = x e y 是连续的,因此 f f f 是可微的(定理 17.5),且 ∇ f ( 2 , 0 ) = ⟨ e 0 , 2 e 0 ⟩ = ⟨ 1 , 2 ⟩ 。 \nabla f(2, 0) = \langle e^0, 2e^0\rangle = \langle 1, 2\rangle\mathclose{\text{。}} ∇ f ( 2 , 0 ) = ⟨ e 0 , 2 e 0 ⟩ = ⟨ 1 , 2 ⟩ 。 从 ( 2 , 0 ) (2, 0) ( 2 , 0 ) 到 ( 5 , 4 ) (5, 4) ( 5 , 4 ) 的方向为 v = ⟨ 3 , 4 ⟩ , \vb{v} = \langle 3, 4\rangle\mathclose{\text{,}} v = ⟨ 3 , 4 ⟩ , 长度为 5,因此该方向的单位向量为 u = v / ∥ v ∥ = ⟨ 3 5 , 4 5 ⟩ 。 \vb{u} = \vb{v}/\norm{\vb{v}} = \big\langle \tfrac35, \tfrac45\big\rangle\mathclose{\text{。}} u = v / ∥ v ∥ = ⟨ 5 3 , 5 4 ⟩ 。 根据定理 17.9,
D u f ( 2 , 0 ) = ⟨ 1 , 2 ⟩ ⋅ ⟨ 3 5 , 4 5 ⟩ = 3 5 + 8 5 = 11 5 = 2.2. \begin{aligned} D_{\vb{u}} f(2, 0) &= \langle 1, 2\rangle\cdot\big\langle \tfrac35, \tfrac45\big\rangle \\ &= \frac35 + \frac85 = \frac{11}{5} = 2.2. \end{aligned} D u f ( 2 , 0 ) = ⟨ 1 , 2 ⟩ ⋅ ⟨ 5 3 , 5 4 ⟩ = 5 3 + 5 8 = 5 11 = 2.2.
从 ( 2 , 0 ) (2, 0) ( 2 , 0 ) 向 ( 5 , 4 ) (5, 4) ( 5 , 4 ) 移动时, f f f 每单位距离增加 2.2 个单位,比沿任一坐标轴(f x = 1 , f_x = 1\mathclose{\text{,}} f x = 1 , f y = 2 ) f_y = 2\mathclose{\text{)}} f y = 2 ) 更快。
最陡上升方向
定理 17.10最速上升方向
设 f f f 在 ( a , b ) (a, b) ( a , b ) 可微,且 ∇ f ( a , b ) ≠ 0 。 \nabla f(a, b) \ne \vb{0}\mathclose{\text{。}} ∇ f ( a , b ) = 0 。 在所有单位向量 u \vb{u} u 给出的方向上,方向导数 D u f ( a , b ) D_{\vb{u}} f(a, b) D u f ( a , b )
当 u \vb{u} u 指向 ∇ f ( a , b ) \nabla f(a, b) ∇ f ( a , b ) 时最大,等于 ∥ ∇ f ( a , b ) ∥ ; \norm{\nabla f(a, b)}\mathclose{\text{;}} ∥ ∇ f ( a , b ) ∥ ;
当 u \vb{u} u 指向相反方向时最小,等于 − ∥ ∇ f ( a , b ) ∥ ; -\norm{\nabla f(a, b)}\mathclose{\text{;}} − ∥ ∇ f ( a , b ) ∥ ;
当 u \vb{u} u 垂直于 ∇ f ( a , b ) \nabla f(a, b) ∇ f ( a , b ) 时为零。
证明
设 θ \theta θ 为 ∇ f ( a , b ) \nabla f(a, b) ∇ f ( a , b ) 与 u \vb{u} u 之间的角。根据定理 17.9 以及点积的角形式(模块 16),
D u f ( a , b ) = ∇ f ( a , b ) ⋅ u = ∥ ∇ f ( a , b ) ∥ ∥ u ∥ cos θ = ∥ ∇ f ( a , b ) ∥ cos θ , \begin{aligned} D_{\vb{u}} f(a, b) &= \nabla f(a, b)\cdot\vb{u} \\ &= \norm{\nabla f(a, b)}\,\norm{\vb{u}}\cos\theta \\ &= \norm{\nabla f(a, b)}\cos\theta, \end{aligned} D u f ( a , b ) = ∇ f ( a , b ) ⋅ u = ∥ ∇ f ( a , b ) ∥ ∥ u ∥ cos θ = ∥ ∇ f ( a , b ) ∥ cos θ ,
因为 ∥ u ∥ = 1 。 \norm{\vb{u}} = 1\mathclose{\text{。}} ∥ u ∥ = 1 。 当 u \vb{u} u 转动时,只有 cos θ \cos\theta cos θ 发生变化。它最大为 1,恰好在 θ = 0 \theta = 0 θ = 0 时;最小为 − 1 , -1\mathclose{\text{,}} − 1 , 恰好在 θ = π \theta = \pi θ = π 时;并在 θ = π / 2 \theta = \pi/2 θ = π /2 时为 0。
∎
因此,非零梯度指向 uphill(上坡),即最陡的方向,其长度为该方向上的斜率。对于 f ( x , y ) = x e y f(x, y) = xe^y f ( x , y ) = x e y 在 ( 2 , 0 ) (2, 0) ( 2 , 0 ) 处(例 17.13),最陡的速率是 ∥ ⟨ 1 , 2 ⟩ ∥ = 5 ≈ 2.236 , \norm{\langle 1, 2\rangle} = \sqrt5 \approx 2.236\mathclose{\text{,}} ∥ ⟨ 1 , 2 ⟩ ∥ = 5 ≈ 2.236 , 方向为 ⟨ 1 , 2 ⟩ / 5 。 \langle 1, 2\rangle/\sqrt5\mathclose{\text{。}} ⟨ 1 , 2 ⟩ / 5 。 向 ( 5 , 4 ) (5, 4) ( 5 , 4 ) 方向的速率 2.2 接近这个值,因为 ⟨ 3 , 4 ⟩ \langle 3, 4\rangle ⟨ 3 , 4 ⟩ 方向与 ⟨ 1 , 2 ⟩ \langle 1, 2\rangle ⟨ 1 , 2 ⟩ 方向之间的夹角约为 10.3 ∘ 10.3^\circ 10. 3 ∘ (cos θ = 2.2 / 5 )。 \cos\theta = 2.2/\sqrt5\mathclose{\text{)。}} cos θ = 2.2/ 5 )。 最快下降的速率 − 5 -\sqrt5 − 5 是在 ⟨ − 1 , − 2 ⟩ / 5 \langle -1, -2\rangle/\sqrt5 ⟨ − 1 , − 2 ⟩ / 5 方向,而在 ± ⟨ 2 , − 1 ⟩ / 5 \pm\langle 2, -1\rangle/\sqrt5 ± ⟨ 2 , − 1 ⟩ / 5 方向上的变化速率为 0。第 17.7 节使用沿 − ∇ f -\nabla f − ∇ f 的步骤来寻找 f f f 的更小值。如果梯度为 0 , \vb{0}\mathclose{\text{,}} 0 , 则每个方向导数都为 0,此时没有唯一的最陡方向。
梯度与等值线
沿着通过 ( a , b ) (a, b) ( a , b ) 的等值线,f f f 没有发生变化,因此其沿该曲线的变化率应为 0。根据定理 17.10,这种情况发生在梯度垂直的方向上。
定理 17.11梯度垂直于等值线
设 f f f 在 ( a , b ) (a, b) ( a , b ) 处可微,且设 r ( t ) = ⟨ x ( t ) , y ( t ) ⟩ \vb{r}(t) = \langle x(t), y(t)\rangle r ( t ) = ⟨ x ( t ) , y ( t )⟩ 是通过 ( a , b ) (a, b) ( a , b ) 的等值线 f ( x , y ) = k f(x, y) = k f ( x , y ) = k 上的一条曲线,且 r ( t 0 ) = ⟨ a , b ⟩ \vb{r}(t_0) = \langle a, b\rangle r ( t 0 ) = ⟨ a , b ⟩ 在 t 0 t_0 t 0 处可微,且 r ′ ( t 0 ) ≠ 0 。 \vb{r}'(t_0) \ne \vb{0}\mathclose{\text{。}} r ′ ( t 0 ) = 0 。 则
∇ f ( a , b ) ⋅ r ′ ( t 0 ) = 0 : \nabla f(a, b)\cdot\vb{r}'(t_0) = 0: ∇ f ( a , b ) ⋅ r ′ ( t 0 ) = 0 :
当梯度非零时,它垂直于等值线的切向量。零梯度满足相同的点积恒等式,但不提供法向方向。
证明
对于每一个 t , t\mathclose{\text{,}} t , f ( x ( t ) , y ( t ) ) = k 。 f\big(x(t), y(t)\big) = k\mathclose{\text{。}} f ( x ( t ) , y ( t ) ) = k 。 对两边在 t 0 t_0 t 0 处求导,左边使用链式法则: f x ( a , b ) x ′ ( t 0 ) + f y ( a , b ) y ′ ( t 0 ) = 0 , f_x(a, b)\,x'(t_0) + f_y(a, b)\,y'(t_0) = 0\mathclose{\text{,}} f x ( a , b ) x ′ ( t 0 ) + f y ( a , b ) y ′ ( t 0 ) = 0 , 即 ∇ f ( a , b ) ⋅ r ′ ( t 0 ) = 0 。 \nabla f(a, b)\cdot\vb{r}'(t_0) = 0\mathclose{\text{。}} ∇ f ( a , b ) ⋅ r ′ ( t 0 ) = 0 。
∎
所以在等高线图中,每个点的梯度(在该点不为 0 \vb{0} 0 时),垂直于通过该点的等高线,并指向数值较大的方向。当等高线代表等间距的值时,等高线密集表示梯度较大,等高线稀疏表示梯度较小(图 17.4,左图)。对于 f ( x , y ) = x 2 + y 2 , f(x, y) = x^2 + y^2\mathclose{\text{,}} f ( x , y ) = x 2 + y 2 , ∇ f = ⟨ 2 x , 2 y ⟩ \nabla f = \langle 2x, 2y\rangle ∇ f = ⟨ 2 x , 2 y ⟩ 指向原点,穿过 x 2 + y 2 = k x^2 + y^2 = k x 2 + y 2 = k 所在的圆,并且与圆垂直;其长度 2 x 2 + y 2 2\sqrt{x^2 + y^2} 2 x 2 + y 2 随着离原点的距离增加而增大,其中对于 k k k 的等间距正数值,圆会密集地排列。
图 17.4 左图:图17.1的等高线图,绘制了三个水平曲线上的梯度,其长度为其实际长度的0.13倍。每个箭头均与其水平曲线垂直相交并指向高处;在等高线密集处箭头最长。右图:从( 3 , 1 ) (3, 1) ( 3 , 1 ) 出发对f ( x , y ) = x 2 + 3 y 2 f(x, y) = x^2 + 3y^2 f ( x , y ) = x 2 + 3 y 2 进行梯度下降(第17.7节)。采用步长η = 0.1 \eta = 0.1 η = 0.1 (蓝色)时,点平滑滑入谷底;采用η = 0.3 \eta = 0.3 η = 0.3 (橙色)时,点则呈之字形穿越谷底,并在陡峭的y y y 方向上发生超调。
水平曲面与切平面
对于三元可微函数,同样成立,其中 ∇ f = ⟨ f x , f y , f z ⟩ \nabla f = \langle f_x, f_y, f_z\rangle ∇ f = ⟨ f x , f y , f z ⟩ 和空间中的单位向量 u \vb{u} u 为: D u f = ∇ f ⋅ u , D_{\vb{u}} f = \nabla f\cdot\vb{u}\mathclose{\text{,}} D u f = ∇ f ⋅ u , 非零梯度指向最陡上升方向,并且根据定理 17.11 的证明(三元情况),它垂直于通过该点且位于等值面上的每一条可微曲线的切向量。一个平面由一点和一个非零法向量确定(模块 16),因此梯度给出正则等值面的切平面。
定义 17.11等值面的切平面
设 P ( x 0 , y 0 , z 0 ) P(x_0, y_0, z_0) P ( x 0 , y 0 , z 0 ) 是等值集 F ( x , y , z ) = k F(x, y, z) = k F ( x , y , z ) = k 上的一点,F F F 在该点的邻域内具有连续的偏导数,且 ∇ F ( P ) ≠ 0 。 \nabla F(P) \ne \vb{0}\mathclose{\text{。}} ∇ F ( P ) = 0 。 由隐函数定理可知,该等值集在这点附近为曲面。它在 P P P 处的切平面 是经过 P P P 且以 ∇ F ( P ) \nabla F(P) ∇ F ( P ) 为法向量的平面:
F x ( P ) ( x − x 0 ) + F y ( P ) ( y − y 0 ) + F z ( P ) ( z − z 0 ) = 0. \begin{aligned} &F_x(P)(x - x_0) + F_y(P)(y - y_0) \\ &\quad + F_z(P)(z - z_0) = 0. \end{aligned} F x ( P ) ( x − x 0 ) + F y ( P ) ( y − y 0 ) + F z ( P ) ( z − z 0 ) = 0.
对于 f f f 具有连续偏导数的情况,图 z = f ( x , y ) z = f(x, y) z = f ( x , y ) 是等值面 F ( x , y , z ) = f ( x , y ) − z = 0 , F(x, y, z) = f(x, y) - z = 0\mathclose{\text{,}} F ( x , y , z ) = f ( x , y ) − z = 0 , 且 ∇ F = ⟨ f x , f y , − 1 ⟩ ; \nabla F = \langle f_x, f_y, -1\rangle\mathclose{\text{;}} ∇ F = ⟨ f x , f y , − 1 ⟩ ; 在 P ( a , b , c ) P(a, b, c) P ( a , b , c ) 处,定义 17.11 给出 f x ( a , b ) ( x − a ) + f y ( a , b ) ( y − b ) − ( z − c ) = 0 , f_x(a, b)(x - a) + f_y(a, b)(y - b) - (z - c) = 0\mathclose{\text{,}} f x ( a , b ) ( x − a ) + f y ( a , b ) ( y − b ) − ( z − c ) = 0 , 即定义 17.6 中的切平面。
例 17.14等值面的切平面 ✓ 已检验
求曲面 x 2 + 2 y 2 + 3 z 2 = 6 x^2 + 2y^2 + 3z^2 = 6 x 2 + 2 y 2 + 3 z 2 = 6 在 P ( 1 , 1 , 1 ) P(1, 1, 1) P ( 1 , 1 , 1 ) 处的切平面,以及该点处的偏导数 ∂ z / ∂ x \partial z/\partial x ∂ z / ∂ x 和 ∂ z / ∂ y 。 \partial z/\partial y\mathclose{\text{。}} ∂ z / ∂ y 。
该点在曲面上,因为 1 + 2 + 3 = 6 。 1 + 2 + 3 = 6\mathclose{\text{。}} 1 + 2 + 3 = 6 。 带入 F ( x , y , z ) = x 2 + 2 y 2 + 3 z 2 , F(x, y, z) = x^2 + 2y^2 + 3z^2\mathclose{\text{,}} F ( x , y , z ) = x 2 + 2 y 2 + 3 z 2 , ∇ F = ⟨ 2 x , 4 y , 6 z ⟩ , \nabla F = \langle 2x, 4y, 6z\rangle\mathclose{\text{,}} ∇ F = ⟨ 2 x , 4 y , 6 z ⟩ , 所以 ∇ F ( 1 , 1 , 1 ) = ⟨ 2 , 4 , 6 ⟩ , \nabla F(1, 1, 1) = \langle 2, 4, 6\rangle\mathclose{\text{,}} ∇ F ( 1 , 1 , 1 ) = ⟨ 2 , 4 , 6 ⟩ , 切平面为
2 ( x − 1 ) + 4 ( y − 1 ) + 6 ( z − 1 ) = 0 , that is, x + 2 y + 3 z = 6. \begin{aligned} 2(x - 1) + 4(y - 1) + 6(z - 1) &= 0, \\ \text{that is,}\quad x + 2y + 3z &= 6. \end{aligned} 2 ( x − 1 ) + 4 ( y − 1 ) + 6 ( z − 1 ) that is, x + 2 y + 3 z = 0 , = 6.
通过隐函数求导(第17.5节), ∂ z ∂ x = − F x F z = − 2 6 = − 1 3 \dfrac{\partial z}{\partial x} = -\dfrac{F_x}{F_z} = -\dfrac{2}{6} = -\dfrac13 ∂ x ∂ z = − F z F x = − 6 2 = − 3 1 和 ∂ z ∂ y = − F y F z = − 4 6 = − 2 3 。 \dfrac{\partial z}{\partial y} = -\dfrac{F_y}{F_z} = -\dfrac46 = -\dfrac23\mathclose{\text{。}} ∂ y ∂ z = − F z F y = − 6 4 = − 3 2 。 两个答案一致:解出 z , z\mathclose{\text{,}} z , 切平面为 z = 2 − 1 3 x − 2 3 y , z = 2 - \tfrac13 x - \tfrac23 y\mathclose{\text{,}} z = 2 − 3 1 x − 3 2 y , 恰好有这些斜率。
注意
方向导数需要单位向量。在例17.13中将 v = ⟨ 3 , 4 ⟩ \vb{v} = \langle 3, 4\rangle v = ⟨ 3 , 4 ⟩ 代入 u , \vb{u}\mathclose{\text{,}} u , ∇ f ⋅ v = 11 , \nabla f\cdot\vb{v} = 11\mathclose{\text{,}} ∇ f ⋅ v = 11 , 五倍于原值,因为 v \vb{v} v 的长度为5:先除以长度。 ∇ f \nabla f ∇ f 是一个向量,不是数字;其长度 ∥ ∇ f ∥ \norm{\nabla f} ∥ ∇ f ∥ 是最陡的斜率。
动手计算使用 SymPy 和 NumPy 计算梯度
一个 SymPy Matrix 保存梯度; .dot 进行点积运算, .norm() 计算长度。例17.13再次:
Python 复制
import sympy as sp
x, y = sp.symbols ('x y' )
f = x*sp.exp (y)
grad = sp.Matrix ([sp.diff (f, x), sp.diff (f, y)])
g = grad.subs ({x: 2 , y: 0 })
u = sp.Matrix ([3 , 4 ])/5
print (grad.T, '|' , g.T, '|' , g.dot (u), '|' , g.norm ())
输出
Matrix([[exp(y), x*exp(y)]]) | Matrix([[1, 2]]) | 11/5 | sqrt(5)
.T 将梯度的列向量转为行向量以便打印: ∇ f = ⟨ e y , x e y ⟩ , \nabla f = \langle e^y, xe^y\rangle\mathclose{\text{,}} ∇ f = ⟨ e y , x e y ⟩ , 然后 ⟨ 1 , 2 ⟩ \langle 1, 2\rangle ⟨ 1 , 2 ⟩ 在 ( 2 , 0 ) , (2, 0)\mathclose{\text{,}} ( 2 , 0 ) , D u f = 11 5 D_{\vb{u}} f = \tfrac{11}{5} D u f = 5 11 和 ∥ ∇ f ∥ = 5 。 \norm{\nabla f} = \sqrt5\mathclose{\text{。}} ∥ ∇ f ∥ = 5 。
定理 17.10 表明,函数在 ∥ ∇ f ∥ = 5 \norm{\nabla f} = \sqrt5 ∥ ∇ f ∥ = 5 方向上增长最快。用 NumPy 每隔 0.5 度取一个方向,共试算 720 个方向:
Python 复制
import numpy as np
gx, gy = 1.0 , 2.0 # grad f(2, 0)
alpha = np.radians (np.arange (0 , 360 , 0.5 )) # the angles of u = <cos a, sin a>
D = gx*np.cos (alpha) + gy*np.sin (alpha) # D_u f for each direction
k = np.argmax (D)
print (f"largest D_u f: {D[k]:.6f}, at {np.degrees(alpha[k])} degrees" )
angle = np.degrees (np.arctan2 (gy, gx)) # the direction of grad f
print (f"|grad f| = {np.hypot(gx, gy):.6f}, at {angle:.4f} degrees" )
输出
largest D_u f: 2.236067, at 63.50000000000001 degrees
|grad f| = 2.236068, at 63.4349 degrees
在 63.5 ∘ 63.5^\circ 63. 5 ∘ 的 720 个方向中,最接近梯度方向 63.4349 ∘ 63.4349^\circ 63.434 9 ∘ 的那个方向,其速率仅在第六位小数处略逊于 ∥ ∇ f ∥ 。 \norm{\nabla f}\mathclose{\text{。}} ∥ ∇ f ∥ 。 (数字 00000000000001 是由于将弧度转换回度数时的浮点数舍入误差。)
第 8.7 节 通过沿导数 x k + 1 = x k − η f ′ ( x k ) x_{k+1} = x_k - \eta f'(x_k) x k + 1 = x k − η f ′ ( x k ) 的反方向进行步进,来最小化单变量函数。在多变量情况下,梯度取代导数,定理 17.10 表示应沿 − ∇ f -\nabla f − ∇ f (最陡下降方向)进行步进。]
定义 17.12梯度下降
要极小化一个含两个或更多变量的可微函数 f , f\mathclose{\text{,}} f , 先选取初始点 x 0 \vb{x}_0 x 0 和步长 η > 0 \eta > 0 η > 0 (学习率),再计算
x k + 1 = x k − η ∇ f ( x k ) , k = 0 , 1 , 2 , … \vb{x}_{k+1} = \vb{x}_k - \eta\,\nabla f(\vb{x}_k), \qquad k = 0, 1, 2, \dots x k + 1 = x k − η ∇ f ( x k ) , k = 0 , 1 , 2 , …
这里 x k = ⟨ x k , y k ⟩ \vb{x}_k = \langle x_k, y_k\rangle x k = ⟨ x k , y k ⟩ 是 k k k 点,写成向量形式,且 f ( x k ) f(\vb{x}_k) f ( x k ) 表示 f ( x k , y k ) 。 f(x_k, y_k)\mathclose{\text{。}} f ( x k , y k ) 。 迭代过程要求每个新点仍保留在 f f f 的定义域内。
当梯度非零时,每一步都沿着最陡下降方向移动,移动的距离为 η ∥ ∇ f ( x k ) ∥ : \eta\norm{\nabla f(\vb{x}_k)}\mathclose{\text{:}} η ∥ ∇ f ( x k ) ∥ : 在曲面陡峭处走长步,在平坦处走短步。根据梯度形式的线性近似(第 17.6 节),
f ( x k + 1 ) ≈ f ( x k ) + ∇ f ( x k ) ⋅ ( x k + 1 − x k ) = f ( x k ) − η ∥ ∇ f ( x k ) ∥ 2 , \begin{aligned} f(\vb{x}_{k+1}) &\approx f(\vb{x}_k) + \nabla f(\vb{x}_k)\cdot(\vb{x}_{k+1} - \vb{x}_k) \\ &= f(\vb{x}_k) - \eta\norm{\nabla f(\vb{x}_k)}^2, \end{aligned} f ( x k + 1 ) ≈ f ( x k ) + ∇ f ( x k ) ⋅ ( x k + 1 − x k ) = f ( x k ) − η ∥ ∇ f ( x k ) ∥ 2 ,
当 ∇ f ( x k ) ≠ 0 \nabla f(\vb{x}_k) \ne \vb{0} ∇ f ( x k ) = 0 时,预测的变化为负。可微性使得误差除以步长趋于 0;在固定这样的点处,对于足够小的 η > 0 , \eta > 0\mathclose{\text{,}} η > 0 , 误差的绝对值小于 1 2 η ∥ ∇ f ( x k ) ∥ 2 , \tfrac12\eta\norm{\nabla f(\vb{x}_k)}^2\mathclose{\text{,}} 2 1 η ∥ ∇ f ( x k ) ∥ 2 , 因此实际变化也为负。需要多小的 η \eta η 取决于点本身。点停止移动仅当 ∇ f = 0 ; \nabla f = \vb{0}\mathclose{\text{;}} ∇ f = 0 ; 模块 18 研究这些临界点。
例 17.15碗状函数上的梯度下降 ✓ 已检验
将梯度下降应用于 f ( x , y ) = x 2 + 3 y 2 , f(x, y) = x^2 + 3y^2\mathclose{\text{,}} f ( x , y ) = x 2 + 3 y 2 , 从 ( 3 , 1 ) (3, 1) ( 3 , 1 ) 出发,初始点为 η = 0.1 。 \eta = 0.1\mathclose{\text{。}} η = 0.1 。 找出第 k k k 个点的公式,以及使点趋近于 ( 0 , 0 ) (0, 0) ( 0 , 0 ) 最小值的步长。
这里 ∇ f = ⟨ 2 x , 6 y ⟩ 。 \nabla f = \langle 2x, 6y\rangle\mathclose{\text{。}} ∇ f = ⟨ 2 x , 6 y ⟩ 。 第一步:∇ f ( 3 , 1 ) = ⟨ 6 , 6 ⟩ , \nabla f(3, 1) = \langle 6, 6\rangle\mathclose{\text{,}} ∇ f ( 3 , 1 ) = ⟨ 6 , 6 ⟩ , 所以
x 1 = ⟨ 3 , 1 ⟩ − 0.1 ⟨ 6 , 6 ⟩ = ⟨ 2.4 , 0.4 ⟩ , \vb{x}_1 = \langle 3, 1\rangle - 0.1\,\langle 6, 6\rangle = \langle 2.4, 0.4\rangle, x 1 = ⟨ 3 , 1 ⟩ − 0.1 ⟨ 6 , 6 ⟩ = ⟨ 2.4 , 0.4 ⟩ ,
且 f f f 从 12 下降到 5.76 + 0.48 = 6.24 。 5.76 + 0.48 = 6.24\mathclose{\text{。}} 5.76 + 0.48 = 6.24 。 第二步:∇ f ( 2.4 , 0.4 ) = ⟨ 4.8 , 2.4 ⟩ , \nabla f(2.4, 0.4) = \langle 4.8, 2.4\rangle\mathclose{\text{,}} ∇ f ( 2.4 , 0.4 ) = ⟨ 4.8 , 2.4 ⟩ , 因此 x 2 = ⟨ 1.92 , 0.16 ⟩ , \vb{x}_2 = \langle 1.92, 0.16\rangle\mathclose{\text{,}} x 2 = ⟨ 1.92 , 0.16 ⟩ , 其中 f = 3.7632 。 f = 3.7632\mathclose{\text{。}} f = 3.7632 。 每一步都将每个坐标乘以一个固定的因子,
x k + 1 = x k − 2 η x k = ( 1 − 2 η ) x k , y k + 1 = y k − 6 η y k = ( 1 − 6 η ) y k , \begin{aligned} x_{k+1} &= x_k - 2\eta x_k = (1 - 2\eta)x_k, \\ y_{k+1} &= y_k - 6\eta y_k = (1 - 6\eta)y_k, \end{aligned} x k + 1 y k + 1 = x k − 2 η x k = ( 1 − 2 η ) x k , = y k − 6 η y k = ( 1 − 6 η ) y k ,
所以对于 η = 0.1 , \eta = 0.1\mathclose{\text{,}} η = 0.1 , x k = 3 ( 0.8 ) k x_k = 3(0.8)^k x k = 3 ( 0.8 ) k 和 y k = ( 0.4 ) k : y_k = (0.4)^k\mathclose{\text{:}} y k = ( 0.4 ) k :
k k k x k x_k x k y k y_k y k f ( x k , y k ) f(x_k, y_k) f ( x k , y k ) 0 0 0 3 3 3 1 1 1 12 12 12 1 1 1 2.4 2.4 2.4 0.4 0.4 0.4 6.24 6.24 6.24 2 2 2 1.92 1.92 1.92 0.16 0.16 0.16 3.7632 3.7632 3.7632 3 3 3 1.536 1.536 1.536 0.064 0.064 0.064 2.37158 2.37158 2.37158 4 4 4 1.2288 1.2288 1.2288 0.0256 0.0256 0.0256 1.51192 1.51192 1.51192 5 5 5 0.98304 0.98304 0.98304 0.01024 0.01024 0.01024 0.966682 0.966682 0.966682 6 6 6 0.786432 0.786432 0.786432 0.004096 0.004096 0.004096 0.618526 0.618526 0.618526
由( 3 , 1 ) (3, 1) ( 3 , 1 ) 可知,点趋近于( 0 , 0 ) (0, 0) ( 0 , 0 ) 当且仅当两个因子均严格介于− 1 -1 − 1 与1之间,如同第8.7节的抛物线,对每个坐标各出现一次。∣ 1 − 2 η ∣ < 1 \abs{1 - 2\eta} < 1 ∣ 1 − 2 η ∣ < 1 需要0 < η < 1 , 0 < \eta < 1\mathclose{\text{,}} 0 < η < 1 , 且∣ 1 − 6 η ∣ < 1 \abs{1 - 6\eta} < 1 ∣ 1 − 6 η ∣ < 1 需要0 < η < 1 3 ; 0 < \eta < \tfrac13\mathclose{\text{;}} 0 < η < 3 1 ; 因此梯度下降在0 < η < 1 3 0 < \eta < \tfrac13 0 < η < 3 1 时恰好收敛。在η = 0.3 \eta = 0.3 η = 0.3 下,因子为0.4和− 0.8 : -0.8\mathclose{\text{:}} − 0.8 : y k y_k y k 在每一步改变符号,点在山谷间之字形摆动并缓慢收敛(图17.4,右侧)。
动手计算使用 NumPy 的梯度下降
每一步是一行:
Python 复制
import numpy as np
def grad (p): # f(x, y) = x**2 + 3*y**2
return np.array ([2 *p[0 ], 6 *p[1 ]])
def descent (eta, steps, p=(3.0 , 1.0 )):
p = np.array (p)
for _ in range (steps):
p = p - eta*grad (p)
return p
for eta in (0.1 , 0.3 ):
for k in (1 , 2 , 5 , 10 , 20 ):
x, y = descent (eta, k)
print (f"eta = {eta}, k = {k:2d}: ({x:9.6f}, {y:9.6f})" )
输出
eta = 0.1, k = 1: ( 2.400000, 0.400000)
eta = 0.1, k = 2: ( 1.920000, 0.160000)
eta = 0.1, k = 5: ( 0.983040, 0.010240)
eta = 0.1, k = 10: ( 0.322123, 0.000105)
eta = 0.1, k = 20: ( 0.034588, 0.000000)
eta = 0.3, k = 1: ( 1.200000, -0.800000)
eta = 0.3, k = 2: ( 0.480000, 0.640000)
eta = 0.3, k = 5: ( 0.030720, -0.327680)
eta = 0.3, k = 10: ( 0.000315, 0.107374)
eta = 0.3, k = 20: ( 0.000000, 0.011529)
用 η = 0.1 \eta = 0.1 η = 0.1 的 y y y 坐标,每一步乘以 0.4,很快变得可以忽略;而 x x x 坐标乘以 0.8,落后很多:在 20 步后仍约为 0.035。用 η = 0.3 \eta = 0.3 η = 0.3 时,角色互换: x x x 每步缩小 0.4 倍,但 y y y 每步改变符号且仅缩小 0.8 倍。不同步长下,需要多少步才能使 ∥ ∇ f ∥ < 10 − 8 \norm{\nabla f} < 10^{-8} ∥ ∇ f ∥ < 1 0 − 8 满足条件?
Python 复制
def steps_needed (eta, tol=1e-8 , max_steps=10000 ):
p = np.array ([3.0 , 1.0 ])
for k in range (max_steps + 1 ):
size = np.linalg.norm (grad (p))
if size < tol:
return k
if size >= 1e6 or k == max_steps:
return None
p = p - eta*grad (p)
for eta in (0.05 , 0.1 , 0.2 , 0.25 , 0.3 , 0.33 , 0.34 ):
k = steps_needed (eta)
print (f"eta = {eta}: " + (f"{k} steps" if k is not None else "tolerance not reached" ))
输出
eta = 0.05: 192 steps
eta = 0.1: 91 steps
eta = 0.2: 40 steps
eta = 0.25: 30 steps
eta = 0.3: 91 steps
eta = 0.33: 1001 steps
eta = 0.34: tolerance not reached
循环最多进行 10,000 次更新,或在梯度增长到 10 6 10^6 1 0 6 时提前终止。这也处理了那些永远不会达到容忍度的有界序列,例如在 η = 1 3 \eta = \tfrac13 η = 3 1 处的振荡; None 表示在停止前未达到容忍度,并不单独证明发散。
这些步长中最好的是0.25,此时因子1 − 2 η = 0.5 1 - 2\eta = 0.5 1 − 2 η = 0.5 和1 − 6 η = − 0.5 1 - 6\eta = -0.5 1 − 6 η = − 0.5 同样小。在η = 0.33 \eta = 0.33 η = 0.33 处,因子1 − 6 η = − 0.98 1 - 6\eta = -0.98 1 − 6 η = − 0.98 接近− 1 , -1\mathclose{\text{,}} − 1 , 且锯齿现象需一千步才能平息;在0.34处,超出1 3 , \tfrac13\mathclose{\text{,}} 3 1 , 它开始增长,梯度下降发散,公式证明了这一点。陡峭方向限制了步长,而平缓方向则希望长步。当不同方向的曲率差异很大时,即使最好的固定步长也会导致缓慢的梯度下降;模块18研究了这个问题,称为病态条件。
在许多机器学习模型中,x \vb{x} x 是权重和偏置等参数组成的列表,参数可能多达数百万个。函数 f f f 表示损失 ,衡量模型在训练数据上的误差。训练常用梯度下降或其变体。随机梯度下降在每一步从训练数据随机抽取一个样本或一个批次,用于估计梯度。动量法和 Adam 在计算下一次更新时还会用到之前各步的梯度。每一步都需要一个梯度,其中每个参数对应一个偏导数。下一节将说明如何高效地计算梯度。人工智能:从机器学习到大语言模型 将这些方法用于实际模型。
神经网络的损失是通过一系列简单的运算计算得到的:权重的乘法、求和以及单变量的简单函数。第5.8 节展示了如何使用双重数对这种计算进行微分,逐个输入向前传播导数。使用这种实现方式,一百万个参数需要进行一百万次运行。对于在输入处可微的运算,反向传播 可以在一次反向传播过程中找到损失相对于每个参数的导数,其计算成本仅为计算损失本身的少量倍数。这是第17.5节中的链式法则,按图结构组织起来。
定义 17.13计算图
A 计算图 是一个无环的有向图:它为每个输入和每个中间结果都有一个节点,每个节点作为另一个节点的输入的使用对应一条箭头。一个节点指向的节点是它的子节点 ,而它是由哪些节点计算得到的则是它的 父节点 。对于可微操作,每条箭头携带一个 局部导数 :即相对于该输入参数的子节点操作的偏导数,其他参数保持不变。如果一个节点提供两个参数,如 e ⋅ e , e\cdot e\mathclose{\text{,}} e ⋅ e , 则会有两条箭头,每条箭头携带 e 。 e\mathclose{\text{。}} e 。 如果计算以数字 L L L 结束,则节点 v v v 的 伴随量 是 v ˉ = ∂ L / ∂ v , \bar v = \partial L/\partial v\mathclose{\text{,}} v ˉ = ∂ L / ∂ v , 读作 “v 条”。
图的计算分为两个阶段进行。
前向传播 计算每个节点的值,从输入到输出,并保存这些值。
反向传播 计算伴随量,从输出反向传播到输入。它从 L ˉ = 1 \bar L = 1 L ˉ = 1 开始,并为每个其他节点 v v v 计算其箭头指向子节点 c c c 的求和,单独统计重复输入的使用次数:
v ˉ = ∑ v → c c ˉ ∂ c ∂ v , \bar v = \sum_{v\to c}\,\bar c\,\frac{\partial c}{\partial v}, v ˉ = v → c ∑ c ˉ ∂ v ∂ c ,
其中每个 ∂ c / ∂ v \partial c/\partial v ∂ c / ∂ v 是该箭头上的局部导数。
为什么这样是对的? L L L 仅通过 v v v 的子节点依赖 v , v\mathclose{\text{,}} v , 因此根据第 17.5 节的一般链式法则,将子节点作为中间变量,正好得到这个求和。展开来看,这是第 17.5 节的核心思想: ∂ L / ∂ v \partial L/\partial v ∂ L / ∂ v 是所有从 v v v 到 L L L 的路径上的局部导数乘积之和。反向传播以经济的方式累加这些乘积。每个伴随量 c ˉ \bar c c ˉ 仅计算一次,然后服务于所有经过 c c c 的路径,因此每个箭头仅使用一次,反向传播的代价是前向传播的少量倍数,无论输入有多少个。
图 17.5 损失 L ( w , b ) = ( 1 − w − b ) 2 + ( 3 − 2 w − b ) 2 L(w, b) = (1 - w - b)^2 + (3 - 2w - b)^2 L ( w , b ) = ( 1 − w − b ) 2 + ( 3 − 2 w − b ) 2 的计算图,如例 17.16 中的 w = b = 0 。 w = b = 0\mathclose{\text{。}} w = b = 0 。 每条箭头表示其局部导数。前向传播给出值(蓝色);从 L ˉ = 1 \bar L = 1 L ˉ = 1 回到输入的反向传播给出伴随量(橙色),而 w ˉ = − 14 \bar w = -14 w ˉ = − 14 和 b ˉ = − 8 \bar b = -8 b ˉ = − 8 是 L L L 的两个偏导数。
例 17.16前向传播和反向传播 ✓ 已检验
一个模型从输入 x x x 预测值 w x + b , wx + b\mathclose{\text{,}} w x + b , 有两个参数 w w w 和 b 。 b\mathclose{\text{。}} b 。 在两个数据点 ( x , t ) = ( 1 , 1 ) (x, t) = (1, 1) ( x , t ) = ( 1 , 1 ) 和 ( 2 , 3 ) (2, 3) ( 2 , 3 ) 上,其中 t t t 是真实值,其误差(真实值减去预测值)分别为 e 1 = 1 − w ⋅ 1 − b e_1 = 1 - w \cdot 1 - b e 1 = 1 − w ⋅ 1 − b 和 e 2 = 3 − w ⋅ 2 − b , e_2 = 3 - w \cdot 2 - b\mathclose{\text{,}} e 2 = 3 − w ⋅ 2 − b , 其损失为 L = e 1 2 + e 2 2 。 L = e_1^2 + e_2^2\mathclose{\text{。}} L = e 1 2 + e 2 2 。 从 w = b = 0 w = b = 0 w = b = 0 开始,通过一次前向传播和一次反向传播(图 17.5)找到 ∂ L / ∂ w \partial L/\partial w ∂ L / ∂ w 和 ∂ L / ∂ b , \partial L/\partial b\mathclose{\text{,}} ∂ L / ∂ b , 并使用 η = 0.05 \eta = 0.05 η = 0.05 进行一次梯度下降更新。
前向传播。 e 1 = 1 , e_1 = 1\mathclose{\text{,}} e 1 = 1 , e 2 = 3 e_2 = 3 e 2 = 3 和 L = 1 + 9 = 10 。 L = 1 + 9 = 10\mathclose{\text{。}} L = 1 + 9 = 10 。
反向传播。 从 L ˉ = 1 \bar L = 1 L ˉ = 1 开始。的 L = e 1 2 + e 2 2 L = e_1^2 + e_2^2 L = e 1 2 + e 2 2 的局部导数是 2 e 1 2e_1 2 e 1 和 2 e 2 , 2e_2\mathclose{\text{,}} 2 e 2 , 因此是 e ˉ 1 = L ˉ ⋅ 2 e 1 = 2 \bar e_1 = \bar L \cdot 2e_1 = 2 e ˉ 1 = L ˉ ⋅ 2 e 1 = 2 和 e ˉ 2 = L ˉ ⋅ 2 e 2 = 6 。 \bar e_2 = \bar L \cdot 2e_2 = 6\mathclose{\text{。}} e ˉ 2 = L ˉ ⋅ 2 e 2 = 6 。 节点 w w w 有两个子节点 e 1 e_1 e 1 和 e 2 , e_2\mathclose{\text{,}} e 2 , 其局部导数为 − 1 -1 − 1 和 − 2 , -2\mathclose{\text{,}} − 2 , 即两点输入 x x x 的负数; b b b 有相同的子节点,其局部导数为 − 1 -1 − 1 和 − 1 : -1\mathclose{\text{:}} − 1 :
w ˉ = e ˉ 1 ⋅ ( − 1 ) + e ˉ 2 ⋅ ( − 2 ) = − 2 − 12 = − 14 , b ˉ = e ˉ 1 ⋅ ( − 1 ) + e ˉ 2 ⋅ ( − 1 ) = − 2 − 6 = − 8. \begin{aligned} \bar w &= \bar e_1 \cdot (-1) + \bar e_2 \cdot (-2) = -2 - 12 = -14, \\ \bar b &= \bar e_1 \cdot (-1) + \bar e_2 \cdot (-1) = -2 - 6 = -8. \end{aligned} w ˉ b ˉ = e ˉ 1 ⋅ ( − 1 ) + e ˉ 2 ⋅ ( − 2 ) = − 2 − 12 = − 14 , = e ˉ 1 ⋅ ( − 1 ) + e ˉ 2 ⋅ ( − 1 ) = − 2 − 6 = − 8.
节点
正向传播
反向传播
w , w\mathclose{\text{,}} w , b b b
0 , 0\mathclose{\text{,}} 0 , 0 0 0
w ˉ = − 14 , \bar w = -14\mathclose{\text{,}} w ˉ = − 14 , b ˉ = − 8 \bar b = -8 b ˉ = − 8
e 1 = 1 − w − b e_1 = 1 - w - b e 1 = 1 − w − b
1 1 1
e ˉ 1 = L ˉ ⋅ 2 e 1 = 2 \bar e_1 = \bar L \cdot 2e_1 = 2 e ˉ 1 = L ˉ ⋅ 2 e 1 = 2
e 2 = 3 − 2 w − b e_2 = 3 - 2w - b e 2 = 3 − 2 w − b
3 3 3
e ˉ 2 = L ˉ ⋅ 2 e 2 = 6 \bar e_2 = \bar L \cdot 2e_2 = 6 e ˉ 2 = L ˉ ⋅ 2 e 2 = 6
L = e 1 2 + e 2 2 L = e_1^2 + e_2^2 L = e 1 2 + e 2 2
10 10 10
L ˉ = 1 \bar L = 1 L ˉ = 1
因此 ∇ L ( 0 , 0 ) = ⟨ − 14 , − 8 ⟩ 。 \nabla L(0, 0) = \langle -14, -8\rangle\mathclose{\text{。}} ∇ L ( 0 , 0 ) = ⟨ − 14 , − 8 ⟩ 。 通过直接对 L ( w , b ) = ( 1 − w − b ) 2 + ( 3 − 2 w − b ) 2 L(w, b) = (1 - w - b)^2 + (3 - 2w - b)^2 L ( w , b ) = ( 1 − w − b ) 2 + ( 3 − 2 w − b ) 2 求导来验证: L w = − 2 ( 1 − w − b ) − 4 ( 3 − 2 w − b ) L_w = -2(1 - w - b) - 4(3 - 2w - b) L w = − 2 ( 1 − w − b ) − 4 ( 3 − 2 w − b ) 和 L b = − 2 ( 1 − w − b ) − 2 ( 3 − 2 w − b ) , L_b = -2(1 - w - b) - 2(3 - 2w - b)\mathclose{\text{,}} L b = − 2 ( 1 − w − b ) − 2 ( 3 − 2 w − b ) , 即 − 2 − 12 = − 14 -2 - 12 = -14 − 2 − 12 = − 14 和 − 2 − 6 = − 8 -2 - 6 = -8 − 2 − 6 = − 8 在 ( 0 , 0 ) (0, 0) ( 0 , 0 ) 处的值。
一次梯度下降步骤得到 ⟨ w , b ⟩ = ⟨ 0 , 0 ⟩ − 0.05 ⟨ − 14 , − 8 ⟩ = ⟨ 0.7 , 0.4 ⟩ , \langle w, b\rangle = \langle 0, 0\rangle - 0.05\,\langle -14, -8\rangle = \langle 0.7, 0.4\rangle\mathclose{\text{,}} ⟨ w , b ⟩ = ⟨ 0 , 0 ⟩ − 0.05 ⟨ − 14 , − 8 ⟩ = ⟨ 0.7 , 0.4 ⟩ , 其中 e 1 = − 0.1 、 e_1 = -0.1\mathclose{\text{、}} e 1 = − 0.1 、 e 2 = 1.2 e_2 = 1.2 e 2 = 1.2 和 L = 0.01 + 1.44 = 1.45 L = 0.01 + 1.44 = 1.45 L = 0.01 + 1.44 = 1.45 从 10 下降到。进一步的步骤接近 w = 2 、 w = 2\mathclose{\text{、}} w = 2 、 b = − 1 , b = -1\mathclose{\text{,}} b = − 1 , 即两点之间的直线 t = 2 x − 1 , t = 2x - 1\mathclose{\text{,}} t = 2 x − 1 , 其中 L = 0 ; L = 0\mathclose{\text{;}} L = 0 ; 模块 18 直接通过最小二乘法找到这样的最佳拟合直线。
注意
每个节点的子节点都会对其邻接点做出贡献。此处 w w w 通过两个数据点同时影响 L ; L\mathclose{\text{;}} L ; 只保留经过 e 1 e_1 e 1 的路径将得到 w ˉ = − 2 \bar w = -2 w ˉ = − 2 而不是 − 14 。 -14\mathclose{\text{。}} − 14 。 因此,一个程序会累积邻接点:每个邻接点初始为 0,每个子节点将其部分加到邻接点上。
动手计算Python 中的反向传播
几行 Python 代码在计算过程中记录图,然后运行反向传播。每个 Var 保存一个值,其父节点保存局部导数,以及其邻接点 grad:
Python 复制
class Var :
"""A node of a computational graph."""
def __init__ (self, value, parents=()):
self.value, self.parents, self.grad = value, parents, 0.0
def __add__ (self, other):
other = other if isinstance (other, Var) else Var (other)
return Var (self.value + other.value, [(self, 1.0 ), (other, 1.0 )])
def __mul__ (self, other):
other = other if isinstance (other, Var) else Var (other)
a, b = self.value, other.value
return Var (a*b, [(self, b), (other, a)])
def __sub__ (self, other):
return self + (-1.0 )*other
def __rsub__ (self, other):
return (-1.0 )*self + other
__radd__, __rmul__ = __add__, __mul__
反向传播按节点顺序排列,使得每个节点在它被计算出的节点之后,将邻接点重置为 0,然后按此列表反向遍历;每个节点将其邻接点乘以局部导数传递给每个父节点,父节点将收到的值相加。重置邻接点使我们可以在同一图上再次运行反向传播:
Python 复制
def backward (out):
order, seen = [], set ()
def visit (v):
if id (v) not in seen:
seen.add (id (v))
for p, _ in v.parents:
visit (p)
order.append (v)
visit (out)
for v in order:
v.grad = 0.0
out.grad = 1.0
for v in reversed (order):
for p, local in v.parents:
p.grad += v.grad*local
示例 17.16,损失由一个普通的 Python 函数计算得出:
Python 复制
data = [(1 , 1 ), (2 , 3 )] # the points (x, t)
def loss (w, b):
L = 0
for x, t in data:
e = t - (w*x + b) # true value minus prediction
L = L + e*e
return L
w, b = Var (0.0 ), Var (0.0 )
L = loss (w, b)
backward (L)
print (L.value, w.grad, b.grad)
乘积 e*e 将 e 列为两次父节点,每次都有局部导数 e , e\mathclose{\text{,}} e , 因此 e 接收 2 e 2e 2 e 倍的乘积的伴随:这就是通过图完成的乘积法则。SymPy 在给定公式的情况下也同意这一点:
Python 复制
import sympy as sp
ws, bs = sp.symbols ('w b' )
Ls = sum ((t - (ws*x + bs))**2 for x, t in data)
print (sp.expand (Ls), '|' , [sp.diff (Ls, v).subs ({ws: 0 , bs: 0 }) for v in (ws, bs)])
输出
2*b**2 + 6*b*w - 8*b + 5*w**2 - 14*w + 10 | [-14, -8]
SymPy 将损失展开为 L = 5 w 2 + 6 w b + 2 b 2 − 14 w − 8 b + 10 , L = 5w^2 + 6wb + 2b^2 - 14w - 8b + 10\mathclose{\text{,}} L = 5 w 2 + 6 w b + 2 b 2 − 14 w − 8 b + 10 , 其中各项按其自身的顺序排列,且在 ( 0 , 0 ) (0, 0) ( 0 , 0 ) 处的偏导数即为反向传播的导数。
训练是一个正向传播、反向传播和梯度下降步骤的循环:
Python 复制
w, b = Var (0.0 ), Var (0.0 )
for step in range (501 ):
L = loss (w, b)
if step in (0 , 1 , 2 , 10 , 100 , 500 ):
Lv, wv, bv = L.value, w.value, b.value
print (f"step {step:3d}: L = {Lv:.3g}, w = {wv:.4f}, b = {bv:.4f}" )
if step < 500 :
backward (L)
w, b = Var (w.value - 0.05 *w.grad), Var (b.value - 0.05 *b.grad)
输出
step 0: L = 10, w = 0.0000, b = 0.0000
step 1: L = 1.45, w = 0.7000, b = 0.4000
step 2: L = 0.59, w = 0.9300, b = 0.5100
step 10: L = 0.393, w = 1.1367, b = 0.3969
step 100: L = 0.0279, w = 1.7700, b = -0.6279
step 500: L = 2.19e-07, w = 1.9994, b = -0.9990
每个打印的步骤都计数了已完成的更新:步骤 0 是起始点,第二行是例 17.16 的步骤。损失在初期迅速下降,随后逐渐变慢:在 100 步后损失仍约为 0.0279,而 w w w 和 b b b 才在 2 和 − 1 -1 − 1 附近稳定下来。该损失的谷底狭长且漫长,这种情况在模块 18 中有解释。
神经网络也有前向和反向两个阶段,只是用数组代替单个数,在各层间使用非线性函数,并且运算次数可能达到数百万次。参数可用梯度下降的变体来更新。人工智能:从机器学习到大语言模型 在模块 2 中讲解神经网络的反向传播。[数学基础模块 18 则用矩阵写出同一条链式法则。
一个二元或三元函数的定义域在平面上或空间中。曲面图展示函数的图像 z = f ( x , y ) ; z = f(x, y)\mathclose{\text{;}} z = f ( x , y ) ; 等高线图展示水平集 f ( x , y ) = k , f(x, y) = k\mathclose{\text{,}} f ( x , y ) = k , 通常是曲线,尽管某些水平可以是点或更大的集合。当等高线等间距时,密集的等高线表示地形陡峭。在三元函数中,水平集 f ( x , y , z ) = k f(x, y, z) = k f ( x , y , z ) = k 通常是曲面。
lim ( x , y ) → ( a , b ) f ( x , y ) = L \lim_{(x,y)\to(a,b)} f(x, y) = L lim ( x , y ) → ( a , b ) f ( x , y ) = L 需要函数值沿定义域中的每条路径都趋于 L 。 L\mathclose{\text{。}} L 。 两条极限不同的路径证明极限不存在;所有直线上的一致并不证明极限存在;夹逼定理 ∣ f − L ∣ ≤ g → 0 \abs{f - L} \le g \to 0 ∣ f − L ∣ ≤ g → 0 证明极限存在。
部分导数 f x = ∂ f / ∂ x f_x = \partial f/\partial x f x = ∂ f / ∂ x 和 f y f_y f y 是通过保持另一个变量固定来求得的;它们是曲面切片的斜率。克莱因定理给出 f x y = f y x , f_{xy} = f_{yx}\mathclose{\text{,}} f x y = f y x , 当混合偏导数在该点的邻域内连续时成立。
对于可微函数,切平面 z = f ( a , b ) + f x ( a , b ) ( x − a ) + f y ( a , b ) ( y − b ) z = f(a, b) + f_x(a, b)(x - a) + f_y(a, b)(y - b) z = f ( a , b ) + f x ( a , b ) ( x − a ) + f y ( a , b ) ( y − b ) 给出线性近似。可微意味着误差除以距离趋于 0;连续偏导数保证这一点,偏导数本身并不足够。全微分 d z = f x d x + f y d y dz = f_x\,dx + f_y\,dy d z = f x d x + f y d y 估计 z z z 的变化,并提供测量误差传播的一阶估计。
对于可微函数,链式法则在树状图中每一条路径增加一个乘积,如 d z d t = ∂ z ∂ x d x d t + ∂ z ∂ y d y d t \dfrac{dz}{dt} = \dfrac{\partial z}{\partial x}\dfrac{dx}{dt} + \dfrac{\partial z}{\partial y}\dfrac{dy}{dt} d t d z = ∂ x ∂ z d t d x + ∂ y ∂ z d t d y 所示。在 F = 0 F = 0 F = 0 和 F y ≠ 0 F_y \ne 0 F y = 0 上某点附近偏导数连续时,隐函数求导给出 d y / d x = − F x / F y dy/dx = -F_x/F_y d y / d x = − F x / F y 的局部图像。
对可微函数 f f f 和一个单位向量 u , \vb{u}\mathclose{\text{,}} u , 梯度 ∇ f = ⟨ f x , f y ⟩ \nabla f = \langle f_x, f_y\rangle ∇ f = ⟨ f x , f y ⟩ 给出 D u f = ∇ f ⋅ u 。 D_{\vb{u}} f = \nabla f\cdot\vb{u}\mathclose{\text{。}} D u f = ∇ f ⋅ u 。 非零梯度指向最陡上升方向,其速率是 ∥ ∇ f ∥ ; \norm{\nabla f}\mathclose{\text{;}} ∥ ∇ f ∥ ; 如果梯度为零,则每个方向导数都为零。在点附近连续偏导数且梯度非零时,等值线在二维情况下是曲线,在三维情况下是曲面,该梯度为其法向量。
梯度下降 x k + 1 = x k − η ∇ f ( x k ) \vb{x}_{k+1} = \vb{x}_k - \eta\nabla f(\vb{x}_k) x k + 1 = x k − η ∇ f ( x k ) 在梯度非零且步长足够小时,可使可微函数下降。较大步长可能导致震荡或发散。反向传播在一个反向遍历过程中,计算损失函数的所有输入偏导数,对每个节点的子节点进行累加:链式法则,用于多个输入的组织。
练习 17.1 ★ 定义域、值域和等值线
设 f ( x , y ) = 16 − x 2 − 4 y 2 。 f(x, y) = \sqrt{16 - x^2 - 4y^2}\mathclose{\text{。}} f ( x , y ) = 16 − x 2 − 4 y 2 。
(a) 找出并描述 f f f 的定义域和值域。
(b) 描述 f ( x , y ) = k f(x, y) = k f ( x , y ) = k 的等值线 k = 0 , 1 , 2 , 3 , 4 。 k = 0, 1, 2, 3, 4\mathclose{\text{。}} k = 0 , 1 , 2 , 3 , 4 。 曲线最密集的地方在哪里?这说明了什么关于曲面?
查看解答✓ 已检验
(a) 开方需要16 − x 2 − 4 y 2 ≥ 0 , 16 - x^2 - 4y^2 \ge 0\mathclose{\text{,}} 16 − x 2 − 4 y 2 ≥ 0 , 即x 2 + 4 y 2 ≤ 16 , x^2 + 4y^2 \le 16\mathclose{\text{,}} x 2 + 4 y 2 ≤ 16 , 或x 2 16 + y 2 4 ≤ 1 : \dfrac{x^2}{16} + \dfrac{y^2}{4} \le 1\mathclose{\text{:}} 16 x 2 + 4 y 2 ≤ 1 : 半轴分别为沿x x x 轴的4和沿y y y 轴的2的椭圆及其内部。在定义域上,16 − x 2 − 4 y 2 16 - x^2 - 4y^2 16 − x 2 − 4 y 2 介于0和16之间,因此f f f 取值于[ 0 , 4 ] ; [0, 4]\mathclose{\text{;}} [ 0 , 4 ] ; 沿x x x 轴,当x x x 从4递减至0时,f ( x , 0 ) = 16 − x 2 f(x, 0) = \sqrt{16 - x^2} f ( x , 0 ) = 16 − x 2 取遍0到4之间的所有值。值域为[ 0 , 4 ] 。 [0, 4]\mathclose{\text{。}} [ 0 , 4 ] 。
(b) 对于0 ≤ k ≤ 4 , 0 \le k \le 4\mathclose{\text{,}} 0 ≤ k ≤ 4 , f ( x , y ) = k f(x, y) = k f ( x , y ) = k 意味着x 2 + 4 y 2 = 16 − k 2 x^2 + 4y^2 = 16 - k^2 x 2 + 4 y 2 = 16 − k 2 (两边平方,二者非负)。对于k < 4 , k < 4\mathclose{\text{,}} k < 4 , 这是一个以原点为中心、半轴为16 − k 2 \sqrt{16 - k^2} 16 − k 2 和1 2 16 − k 2 \tfrac12\sqrt{16 - k^2} 2 1 16 − k 2 的椭圆,形状始终相同。对于k = 0 , k = 0\mathclose{\text{,}} k = 0 , 它是定义域的边界。它在正x x x 轴上于4、15 ≈ 3.87 、 \sqrt{15} \approx 3.87\mathclose{\text{、}} 15 ≈ 3.87 、 12 ≈ 3.46 \sqrt{12} \approx 3.46 12 ≈ 3.46 和7 ≈ 2.65 \sqrt7 \approx 2.65 7 ≈ 2.65 处相交,对应于k = 0 , 1 , 2 , 3 ; k = 0, 1, 2, 3\mathclose{\text{;}} k = 0 , 1 , 2 , 3 ; 对于k = 4 , k = 4\mathclose{\text{,}} k = 4 , 水平集是单个点( 0 , 0 ) , (0, 0)\mathclose{\text{,}} ( 0 , 0 ) , 即顶点。间隙从约0.13增大到0.41、0.82和2.65:水平曲线在边缘附近最密集,此处曲面(椭球的上半部分)最陡峭。
练习 17.2 ★ 偏导数
求所有一阶偏导数:
(a) f ( x , y ) = x 4 y − 3 x 2 y 3 + 7 , f(x, y) = x^4y - 3x^2y^3 + 7\mathclose{\text{,}} f ( x , y ) = x 4 y − 3 x 2 y 3 + 7 , 及其在 ( 1 , − 1 ) (1, -1) ( 1 , − 1 ) 处的值
(b) g ( x , y ) = ln ( x 2 + y 2 ) g(x, y) = \ln(x^2 + y^2) g ( x , y ) = ln ( x 2 + y 2 )
(c) h ( x , y , z ) = x y 2 z h(x, y, z) = \dfrac{xy^2}{z} h ( x , y , z ) = z x y 2
查看解答✓ 已检验
(a) 保持 y y y 固定, f x = 4 x 3 y − 6 x y 3 ; f_x = 4x^3y - 6xy^3\mathclose{\text{;}} f x = 4 x 3 y − 6 x y 3 ; 保持 x x x 固定, f y = x 4 − 9 x 2 y 2 。 f_y = x^4 - 9x^2y^2\mathclose{\text{。}} f y = x 4 − 9 x 2 y 2 。 在 ( 1 , − 1 ) : (1, -1)\mathclose{\text{:}} ( 1 , − 1 ) : f x = − 4 + 6 = 2 f_x = -4 + 6 = 2 f x = − 4 + 6 = 2 和 f y = 1 − 9 = − 8 。 f_y = 1 - 9 = -8\mathclose{\text{。}} f y = 1 − 9 = − 8 。
(b) 根据链式法则,内函数为 x 2 + y 2 , x^2 + y^2\mathclose{\text{,}} x 2 + y 2 , 导数为 1 / u 1/u 1/ u 的 ln u : \ln u\mathclose{\text{:}} ln u : g x = 2 x x 2 + y 2 g_x = \dfrac{2x}{x^2 + y^2} g x = x 2 + y 2 2 x 和 g y = 2 y x 2 + y 2 , g_y = \dfrac{2y}{x^2 + y^2}\mathclose{\text{,}} g y = x 2 + y 2 2 y , 对于 ( x , y ) ≠ ( 0 , 0 ) 。 (x, y) \ne (0, 0)\mathclose{\text{。}} ( x , y ) = ( 0 , 0 ) 。
(c) 对于 z ≠ 0 : z \ne 0\mathclose{\text{:}} z = 0 : h x = y 2 z h_x = \dfrac{y^2}{z} h x = z y 2 和 h y = 2 x y z , h_y = \dfrac{2xy}{z}\mathclose{\text{,}} h y = z 2 x y , 因为 1 z \dfrac{1}{z} z 1 是 z z z 固定时的常数因子;以及 h z = − x y 2 z 2 , h_z = -\dfrac{xy^2}{z^2}\mathclose{\text{,}} h z = − z 2 x y 2 , 常数 x y 2 xy^2 x y 2 乘以 1 z \dfrac1z z 1 的导数。使用商法则虽然可以得到相同答案,但需要更多步骤。
练习 17.3 ★ 两个极限
(a) 证明 lim ( x , y ) → ( 0 , 0 ) x 2 − y 2 x 2 + y 2 \lim_{(x, y)\to(0, 0)} \dfrac{x^2 - y^2}{x^2 + y^2} lim ( x , y ) → ( 0 , 0 ) x 2 + y 2 x 2 − y 2 不存在。
(b) 求 lim ( x , y ) → ( 0 , 0 ) x 2 + y 2 x 2 + y 2 + 1 − 1 。 \lim_{(x, y)\to(0, 0)} \dfrac{x^2 + y^2}{\sqrt{x^2 + y^2 + 1} - 1}\mathclose{\text{。}} lim ( x , y ) → ( 0 , 0 ) x 2 + y 2 + 1 − 1 x 2 + y 2 。
查看解答✓ 已检验
(a) 沿着 x x x 轴(y = 0 , y = 0\mathclose{\text{,}} y = 0 , x ≠ 0 ) x \ne 0\mathclose{\text{)}} x = 0 ) 函数为 x 2 x 2 = 1 ; \dfrac{x^2}{x^2} = 1\mathclose{\text{;}} x 2 x 2 = 1 ; 沿着 y y y 轴它为 − y 2 y 2 = − 1 。 \dfrac{-y^2}{y^2} = -1\mathclose{\text{。}} y 2 − y 2 = − 1 。 两条路径给出不同的极限,因此根据定理 17.1 极限不存在。(沿 y = m x y = mx y = m x 为 1 − m 2 1 + m 2 , \dfrac{1 - m^2}{1 + m^2}\mathclose{\text{,}} 1 + m 2 1 − m 2 , 这取决于 m 。) m\mathclose{\text{。)}} m 。)
(b) 直接代入得到 0 0 。 \tfrac00\mathclose{\text{。}} 0 0 。 函数仅通过 s = x 2 + y 2 s = x^2 + y^2 s = x 2 + y 2 依赖于 x x x 和 y , y\mathclose{\text{,}} y , 因此可以参照 第 2.5 节 :对于 s > 0 , s > 0\mathclose{\text{,}} s > 0 ,
s s + 1 − 1 = s ( s + 1 + 1 ) ( s + 1 ) − 1 = s + 1 + 1. \begin{aligned} \frac{s}{\sqrt{s + 1} - 1} &= \frac{s\big(\sqrt{s + 1} + 1\big)}{(s + 1) - 1} \\ &= \sqrt{s + 1} + 1. \end{aligned} s + 1 − 1 s = ( s + 1 ) − 1 s ( s + 1 + 1 ) = s + 1 + 1.
( x , y ) → ( 0 , 0 ) , (x, y) \to (0, 0)\mathclose{\text{,}} ( x , y ) → ( 0 , 0 ) , s → 0 , s \to 0\mathclose{\text{,}} s → 0 , 和 x 2 + y 2 + 1 + 1 \sqrt{x^2 + y^2 + 1} + 1 x 2 + y 2 + 1 + 1 在原点处连续且值为 2。极限为 2。
练习 17.4 ★ 梯度及其方向
设 f ( x , y ) = x 2 y − y 3 。 f(x, y) = x^2y - y^3\mathclose{\text{。}} f ( x , y ) = x 2 y − y 3 。
(a) 求 ∇ f ( 2 , 1 ) 。 \nabla f(2, 1)\mathclose{\text{。}} ∇ f ( 2 , 1 ) 。
(b) 求 f f f 在 ( 2 , 1 ) (2, 1) ( 2 , 1 ) 处沿 ⟨ 1 , − 1 ⟩ \langle 1, -1\rangle ⟨ 1 , − 1 ⟩ 方向的方向导数。
(c) f f f 在 ( 2 , 1 ) (2, 1) ( 2 , 1 ) 处哪个方向增加最快,速率是多少?速率为 0 的方向是哪些?
查看解答✓ 已检验
(a) f x = 2 x y f_x = 2xy f x = 2 x y 和 f y = x 2 − 3 y 2 , f_y = x^2 - 3y^2\mathclose{\text{,}} f y = x 2 − 3 y 2 , 所以 ∇ f ( 2 , 1 ) = ⟨ 4 , 4 − 3 ⟩ = ⟨ 4 , 1 ⟩ 。 \nabla f(2, 1) = \langle 4, 4 - 3\rangle = \langle 4, 1\rangle\mathclose{\text{。}} ∇ f ( 2 , 1 ) = ⟨ 4 , 4 − 3 ⟩ = ⟨ 4 , 1 ⟩ 。
(b) ⟨ 1 , − 1 ⟩ \langle 1, -1\rangle ⟨ 1 , − 1 ⟩ 的长度为 2 , \sqrt2\mathclose{\text{,}} 2 , 所以 u = ⟨ 1 , − 1 ⟩ / 2 , \vb{u} = \langle 1, -1\rangle/\sqrt2\mathclose{\text{,}} u = ⟨ 1 , − 1 ⟩ / 2 , 并且根据定理 17.9
D u f ( 2 , 1 ) = 4 ⋅ 1 + 1 ⋅ ( − 1 ) 2 = 3 2 ≈ 2.121. D_{\vb{u}} f(2, 1) = \frac{4 \cdot 1 + 1 \cdot (-1)}{\sqrt2} = \frac{3}{\sqrt2} \approx 2.121. D u f ( 2 , 1 ) = 2 4 ⋅ 1 + 1 ⋅ ( − 1 ) = 2 3 ≈ 2.121.
使用 ⟨ 1 , − 1 ⟩ \langle 1, -1\rangle ⟨ 1 , − 1 ⟩ 本身会得到 3,这是错误的:它不是单位法向量。
(c) 最快增加方向为 ∇ f ( 2 , 1 ) , \nabla f(2, 1)\mathclose{\text{,}} ∇ f ( 2 , 1 ) , 即 u = ⟨ 4 , 1 ⟩ / 17 , \vb{u} = \langle 4, 1\rangle/\sqrt{17}\mathclose{\text{,}} u = ⟨ 4 , 1 ⟩ / 17 , 速率为 ∥ ⟨ 4 , 1 ⟩ ∥ = 17 ≈ 4.123 \norm{\langle 4, 1\rangle} = \sqrt{17} \approx 4.123 ∥ ⟨ 4 , 1 ⟩ ∥ = 17 ≈ 4.123 (定理 17.10)。速率为 0 的方向是梯度 ± ⟨ 1 , − 4 ⟩ / 17 \pm\langle 1, -4\rangle/\sqrt{17} ± ⟨ 1 , − 4 ⟩ / 17 垂直的两个方向,即通过 ( 2 , 1 ) (2, 1) ( 2 , 1 ) 的等值线的切向方向:确实为 ⟨ 4 , 1 ⟩ ⋅ ⟨ 1 , − 4 ⟩ = 4 − 4 = 0 。 \langle 4, 1\rangle\cdot\langle 1, -4\rangle = 4 - 4 = 0\mathclose{\text{。}} ⟨ 4 , 1 ⟩ ⋅ ⟨ 1 , − 4 ⟩ = 4 − 4 = 0 。
练习 17.5 ★★ 通过夹逼法求极限
证明 lim ( x , y ) → ( 0 , 0 ) x 3 + y 3 x 2 + y 2 = 0 。 \lim_{(x, y)\to(0, 0)} \dfrac{x^3 + y^3}{x^2 + y^2} = 0\mathclose{\text{。}} lim ( x , y ) → ( 0 , 0 ) x 2 + y 2 x 3 + y 3 = 0 。
查看解答✓ 已检验
设 ( x , y ) ≠ ( 0 , 0 ) , (x, y) \ne (0, 0)\mathclose{\text{,}} ( x , y ) = ( 0 , 0 ) , 并记 ρ = x 2 + y 2 \rho = \sqrt{x^2 + y^2} ρ = x 2 + y 2 为它到原点的距离。由于 ∣ x ∣ ≤ ρ , \abs{x} \le \rho\mathclose{\text{,}} ∣ x ∣ ≤ ρ , 有 ∣ x 3 ∣ = ∣ x ∣ x 2 ≤ ρ x 2 。 \abs{x^3} = \abs{x}\,x^2 \le \rho\,x^2\mathclose{\text{。}} x 3 = ∣ x ∣ x 2 ≤ ρ x 2 。 同理有 ∣ y 3 ∣ ≤ ρ y 2 。 \abs{y^3} \le \rho\,y^2\mathclose{\text{。}} y 3 ≤ ρ y 2 。 所以
∣ x 3 + y 3 x 2 + y 2 ∣ ≤ ∣ x 3 ∣ + ∣ y 3 ∣ x 2 + y 2 ≤ ρ ( x 2 + y 2 ) x 2 + y 2 = ρ . \begin{aligned} \abs{\frac{x^3 + y^3}{x^2 + y^2}} &\le \frac{\abs{x^3} + \abs{y^3}}{x^2 + y^2} \\ &\le \frac{\rho\,(x^2 + y^2)}{x^2 + y^2} = \rho. \end{aligned} x 2 + y 2 x 3 + y 3 ≤ x 2 + y 2 x 3 + y 3 ≤ x 2 + y 2 ρ ( x 2 + y 2 ) = ρ .
由( x , y ) → ( 0 , 0 ) 、 (x, y) \to (0, 0)\mathclose{\text{、}} ( x , y ) → ( 0 , 0 ) 、 ρ → 0 , \rho \to 0\mathclose{\text{,}} ρ → 0 , 根据夹逼定理(定理17.2,其中g = ρ g = \rho g = ρ 和L = 0 ) L = 0\mathclose{\text{)}} L = 0 ) 可知极限为0。检验路径仅能提示答案:沿y = m x y = mx y = m x 函数为( 1 + m 3 ) x 1 + m 2 , \dfrac{(1 + m^3)x}{1 + m^2}\mathclose{\text{,}} 1 + m 2 ( 1 + m 3 ) x , 其趋于0,但例17.3后的陷阱表明,仅凭直线无法证明任何结论。
练习 17.6 ★★ 切平面与一个估计
设 f ( x , y ) = x e x y 。 f(x, y) = xe^{xy}\mathclose{\text{。}} f ( x , y ) = x e x y 。
(a) 求曲面 z = f ( x , y ) z = f(x, y) z = f ( x , y ) 在 ( 1 , 0 , 1 ) (1, 0, 1) ( 1 , 0 , 1 ) 处的切平面。
(b) 使用线性近似估计 f ( 1.1 , − 0.1 ) , f(1.1, -0.1)\mathclose{\text{,}} f ( 1.1 , − 0.1 ) , 并与计算器上的值进行比较。
查看解答✓ 已检验
(a) 根据乘积法则和链式法则,f x = e x y + x y e x y = ( 1 + x y ) e x y f_x = e^{xy} + xye^{xy} = (1 + xy)e^{xy} f x = e x y + x y e x y = ( 1 + x y ) e x y 和 f y = x ⋅ x e x y = x 2 e x y , f_y = x \cdot xe^{xy} = x^2e^{xy}\mathclose{\text{,}} f y = x ⋅ x e x y = x 2 e x y , 两者在全平面连续。在 ( 1 , 0 ) (1, 0) ( 1 , 0 ) 处:f ( 1 , 0 ) = 1 , f(1, 0) = 1\mathclose{\text{,}} f ( 1 , 0 ) = 1 , f x ( 1 , 0 ) = 1 f_x(1, 0) = 1 f x ( 1 , 0 ) = 1 和 f y ( 1 , 0 ) = 1 。 f_y(1, 0) = 1\mathclose{\text{。}} f y ( 1 , 0 ) = 1 。 切平面为 z = 1 + ( x − 1 ) + ( y − 0 ) , z = 1 + (x - 1) + (y - 0)\mathclose{\text{,}} z = 1 + ( x − 1 ) + ( y − 0 ) , 即 z = x + y 。 z = x + y\mathclose{\text{。}} z = x + y 。
(b) f ( 1.1 , − 0.1 ) ≈ 1.1 + ( − 0.1 ) = 1 . f(1.1, -0.1) \approx 1.1 + (-0.1) = 1\mathclose{\text{.}} f ( 1.1 , − 0.1 ) ≈ 1.1 + ( − 0.1 ) = 1 . 一台计算器给出 1.1 e − 0.11 ≈ 0.98542 , 1.1e^{-0.11} \approx 0.98542\mathclose{\text{,}} 1.1 e − 0.11 ≈ 0.98542 , 因此误差(精确值减去近似值)为 1.1 e − 0.11 − 1 ≈ − 0.015 : 1.1e^{-0.11} - 1 \approx -0.015\mathclose{\text{:}} 1.1 e − 0.11 − 1 ≈ − 0.015 : 估计值过高。该点到 ( 1 , 0 ) (1, 0) ( 1 , 0 ) 的距离为 0.1 2 + 0.1 2 ≈ 0.14 。 \sqrt{0.1^2 + 0.1^2} \approx 0.14\mathclose{\text{。}} 0. 1 2 + 0. 1 2 ≈ 0.14 。 距离本身并不能说明线性近似有多准确;此处通过与计算值的比较显示出其准确性。
练习 17.7 ★★ 三个路径的链式法则
设 w = x 2 + y z , w = x^2 + yz\mathclose{\text{,}} w = x 2 + y z , 其中 x = t 2 , x = t^2\mathclose{\text{,}} x = t 2 , y = cos t y = \cos t y = cos t 和 z = sin t 。 z = \sin t\mathclose{\text{。}} z = sin t 。
(a) 画出树状图,并利用它将 d w / d t dw/dt d w / d t 表示为 t t t 的函数。
(b) 通过代入进行验证。
(c) 求 d w / d t dw/dt d w / d t 在 t = 0 t = 0 t = 0 和 t = π / 4 t = \pi/4 t = π /4 处的值。
查看解答✓ 已检验
(a) 树状图顶部为 w , w\mathclose{\text{,}} w , 向下有三条分支分别到达 x , x\mathclose{\text{,}} x , y y y 和 z , z\mathclose{\text{,}} z , 分别标记为 w x = 2 x , w_x = 2x\mathclose{\text{,}} w x = 2 x , w y = z w_y = z w y = z 和 w z = y , w_z = y\mathclose{\text{,}} w z = y , 从这些点再向下各有一条分支到达 t , t\mathclose{\text{,}} t , 分别标记为 d x / d t = 2 t , dx/dt = 2t\mathclose{\text{,}} d x / d t = 2 t , d y / d t = − sin t dy/dt = -\sin t d y / d t = − sin t 和 d z / d t = cos t 。 dz/dt = \cos t\mathclose{\text{。}} d z / d t = cos t 。 三条路径给出三个乘积:
d w d t = 2 x ⋅ 2 t + z ⋅ ( − sin t ) + y cos t = 4 t 3 − sin 2 t + cos 2 t = 4 t 3 + cos 2 t , \begin{aligned} \frac{dw}{dt} &= 2x\cdot 2t + z\cdot(-\sin t) + y\cos t \\ &= 4t^3 - \sin^2 t + \cos^2 t = 4t^3 + \cos 2t, \end{aligned} d t d w = 2 x ⋅ 2 t + z ⋅ ( − sin t ) + y cos t = 4 t 3 − sin 2 t + cos 2 t = 4 t 3 + cos 2 t ,
模块 1 的加法公式,使用 x = t 2 , x = t^2\mathclose{\text{,}} x = t 2 , y = cos t , y = \cos t\mathclose{\text{,}} y = cos t , z = sin t z = \sin t z = sin t 和 cos 2 t − sin 2 t = cos 2 t \cos^2 t - \sin^2 t = \cos 2t cos 2 t − sin 2 t = cos 2 t (两个角 t t t 的加法公式)。
(b) w = t 4 + cos t sin t = t 4 + 1 2 sin 2 t , w = t^4 + \cos t\sin t = t^4 + \tfrac12\sin 2t\mathclose{\text{,}} w = t 4 + cos t sin t = t 4 + 2 1 sin 2 t , 因此 d w d t = 4 t 3 + cos 2 t , \dfrac{dw}{dt} = 4t^3 + \cos 2t\mathclose{\text{,}} d t d w = 4 t 3 + cos 2 t , 如 (a) 所示。
(c) 在 t = 0 : t = 0\mathclose{\text{:}} t = 0 : d w d t = 0 + 1 = 1 。 \dfrac{dw}{dt} = 0 + 1 = 1\mathclose{\text{。}} d t d w = 0 + 1 = 1 。 在 t = π / 4 : t = \pi/4\mathclose{\text{:}} t = π /4 : 4 ( π 4 ) 3 + cos π 2 = π 3 16 ≈ 1.938 。 4\Big(\dfrac{\pi}{4}\Big)^3 + \cos\dfrac{\pi}{2} = \dfrac{\pi^3}{16} \approx 1.938\mathclose{\text{。}} 4 ( 4 π ) 3 + cos 2 π = 16 π 3 ≈ 1.938 。
练习 17.8 ★★ 一个等值面
点 ( 1 , 2 , 3 ) (1, 2, 3) ( 1 , 2 , 3 ) 位于曲面 x y z = 6 xyz = 6 x y z = 6 上。
(a) 求该曲面在该点的切平面。
(b) 在 ( 1 , 2 , 3 ) (1, 2, 3) ( 1 , 2 , 3 ) 附近,曲面是函数 z ( x , y ) z(x, y) z ( x , y ) 的图像。通过隐函数求导,求 ∂ z / ∂ x \partial z/\partial x ∂ z / ∂ x 和 ∂ z / ∂ y \partial z/\partial y ∂ z / ∂ y 在 ( 1 , 2 ) (1, 2) ( 1 , 2 ) 处的值。
(c) 用两种方法验证 (b):使用 (a) 的切平面,以及通过求解 z z z 来验证。
查看解答✓ 已检验
(a) 用 F ( x , y , z ) = x y z , F(x, y, z) = xyz\mathclose{\text{,}} F ( x , y , z ) = x y z , ∇ F = ⟨ y z , x z , x y ⟩ , \nabla F = \langle yz, xz, xy\rangle\mathclose{\text{,}} ∇ F = ⟨ y z , x z , x y ⟩ , 因此 ∇ F ( 1 , 2 , 3 ) = ⟨ 6 , 3 , 2 ⟩ 。 \nabla F(1, 2, 3) = \langle 6, 3, 2\rangle\mathclose{\text{。}} ∇ F ( 1 , 2 , 3 ) = ⟨ 6 , 3 , 2 ⟩ 。 切平面为
6 ( x − 1 ) + 3 ( y − 2 ) + 2 ( z − 3 ) = 0 , that is, 6 x + 3 y + 2 z = 18. \begin{aligned} 6(x - 1) + 3(y - 2) + 2(z - 3) &= 0, \\ \text{that is,}\quad 6x + 3y + 2z &= 18. \end{aligned} 6 ( x − 1 ) + 3 ( y − 2 ) + 2 ( z − 3 ) that is, 6 x + 3 y + 2 z = 0 , = 18.
(b) F z ( 1 , 2 , 3 ) = 2 ≠ 0 , F_z(1, 2, 3) = 2 \ne 0\mathclose{\text{,}} F z ( 1 , 2 , 3 ) = 2 = 0 , 因此 ∂ z ∂ x = − F x F z = − 6 2 = − 3 \dfrac{\partial z}{\partial x} = -\dfrac{F_x}{F_z} = -\dfrac62 = -3 ∂ x ∂ z = − F z F x = − 2 6 = − 3 和 ∂ z ∂ y = − F y F z = − 3 2 。 \dfrac{\partial z}{\partial y} = -\dfrac{F_y}{F_z} = -\dfrac32\mathclose{\text{。}} ∂ y ∂ z = − F z F y = − 2 3 。
(c) 解出 z , z\mathclose{\text{,}} z , 切平面为 z = 9 − 3 x − 3 2 y , z = 9 - 3x - \tfrac32 y\mathclose{\text{,}} z = 9 − 3 x − 2 3 y , 其斜率为 − 3 -3 − 3 和 − 3 2 。 -\tfrac32\mathclose{\text{。}} − 2 3 。 并且 z = 6 x y , z = \dfrac{6}{xy}\mathclose{\text{,}} z = x y 6 , 所以在 ( 1 , 2 ) (1, 2) ( 1 , 2 ) 处, z x = − 6 x 2 y = − 6 2 = − 3 z_x = -\dfrac{6}{x^2y} = -\dfrac62 = -3 z x = − x 2 y 6 = − 2 6 = − 3 和 z y = − 6 x y 2 = − 6 4 = − 3 2 。 z_y = -\dfrac{6}{xy^2} = -\dfrac64 = -\dfrac32\mathclose{\text{。}} z y = − x y 2 6 = − 4 6 = − 2 3 。
练习 17.9 ★★ 拉普拉斯方程
证明 u ( x , y ) = ln ( x 2 + y 2 ) u(x, y) = \ln(x^2 + y^2) u ( x , y ) = ln ( x 2 + y 2 ) 满足拉普拉斯方程 u x x + u y y = 0 u_{xx} + u_{yy} = 0 u xx + u y y = 0 对于 ( x , y ) ≠ ( 0 , 0 ) , (x, y) \ne (0, 0)\mathclose{\text{,}} ( x , y ) = ( 0 , 0 ) , 并验证 u x y = u y x 。 u_{xy} = u_{yx}\mathclose{\text{。}} u x y = u y x 。
查看解答✓ 已检验
由练习 17.2(b), u x = 2 x x 2 + y 2 u_x = \dfrac{2x}{x^2 + y^2} u x = x 2 + y 2 2 x 和 u y = 2 y x 2 + y 2 。 u_y = \dfrac{2y}{x^2 + y^2}\mathclose{\text{。}} u y = x 2 + y 2 2 y 。 根据商法则,保持 y y y 不变,
u x x = 2 ( x 2 + y 2 ) − 2 x ⋅ 2 x ( x 2 + y 2 ) 2 = 2 ( y 2 − x 2 ) ( x 2 + y 2 ) 2 , \begin{aligned} u_{xx} &= \frac{2(x^2 + y^2) - 2x\cdot 2x}{(x^2 + y^2)^2} \\ &= \frac{2(y^2 - x^2)}{(x^2 + y^2)^2}, \end{aligned} u xx = ( x 2 + y 2 ) 2 2 ( x 2 + y 2 ) − 2 x ⋅ 2 x = ( x 2 + y 2 ) 2 2 ( y 2 − x 2 ) ,
同样地,保持 x x x 不变, u y y = 2 ( x 2 − y 2 ) ( x 2 + y 2 ) 2 。 u_{yy} = \dfrac{2(x^2 - y^2)}{(x^2 + y^2)^2}\mathclose{\text{。}} u y y = ( x 2 + y 2 ) 2 2 ( x 2 − y 2 ) 。 两者相消: u x x + u y y = 0 。 u_{xx} + u_{yy} = 0\mathclose{\text{。}} u xx + u y y = 0 。
对于混合偏导数,当 x x x 保持不变时, u x u_x u x 的分子 2 x 2x 2 x 是常数,因此
u x y = 2 x ⋅ − 2 y ( x 2 + y 2 ) 2 = − 4 x y ( x 2 + y 2 ) 2 , u_{xy} = 2x\cdot\frac{-2y}{(x^2 + y^2)^2} = -\frac{4xy}{(x^2 + y^2)^2}, u x y = 2 x ⋅ ( x 2 + y 2 ) 2 − 2 y = − ( x 2 + y 2 ) 2 4 x y ,
同样地, u y x = 2 y ⋅ − 2 x ( x 2 + y 2 ) 2 = − 4 x y ( x 2 + y 2 ) 2 。 u_{yx} = 2y\cdot\dfrac{-2x}{(x^2 + y^2)^2} = -\dfrac{4xy}{(x^2 + y^2)^2}\mathclose{\text{。}} u y x = 2 y ⋅ ( x 2 + y 2 ) 2 − 2 x = − ( x 2 + y 2 ) 2 4 x y 。 它们相等,正如克莱因定理所预测的:两者在原点以外都是连续的。
练习 17.10 ★★★ 当克莱因定理不适用时
设 f ( x , y ) = x y ( x 2 − y 2 ) x 2 + y 2 f(x, y) = \dfrac{xy(x^2 - y^2)}{x^2 + y^2} f ( x , y ) = x 2 + y 2 x y ( x 2 − y 2 ) 对于 ( x , y ) ≠ ( 0 , 0 ) , (x, y) \ne (0, 0)\mathclose{\text{,}} ( x , y ) = ( 0 , 0 ) , 且 f ( 0 , 0 ) = 0 . f(0, 0) = 0\mathclose{\text{.}} f ( 0 , 0 ) = 0 .
(a) 证明 f x ( 0 , y ) = − y f_x(0, y) = -y f x ( 0 , y ) = − y 对于每一个 y , y\mathclose{\text{,}} y , 并且 f y ( x , 0 ) = x f_y(x, 0) = x f y ( x , 0 ) = x 对于每一个 x 。 x\mathclose{\text{。}} x 。
(b) 推导出 f x y ( 0 , 0 ) = − 1 f_{xy}(0, 0) = -1 f x y ( 0 , 0 ) = − 1 和 f y x ( 0 , 0 ) = 1 。 f_{yx}(0, 0) = 1\mathclose{\text{。}} f y x ( 0 , 0 ) = 1 。
(c) 哪个克莱因定理的假设不成立?
查看解答✓ 已检验
(a) 固定 y ≠ 0 。 y \ne 0\mathclose{\text{。}} y = 0 。 由于 f ( 0 , y ) = 0 , f(0, y) = 0\mathclose{\text{,}} f ( 0 , y ) = 0 , 定义给出
f x ( 0 , y ) = lim h → 0 f ( h , y ) − 0 h = lim h → 0 y ( h 2 − y 2 ) h 2 + y 2 = y ( − y 2 ) y 2 = − y , \begin{aligned} f_x(0, y) &= \lim_{h\to0}\frac{f(h, y) - 0}{h} = \lim_{h\to0}\frac{y(h^2 - y^2)}{h^2 + y^2} \\ &= \frac{y(-y^2)}{y^2} = -y, \end{aligned} f x ( 0 , y ) = h → 0 lim h f ( h , y ) − 0 = h → 0 lim h 2 + y 2 y ( h 2 − y 2 ) = y 2 y ( − y 2 ) = − y ,
通过直接代入,由于分母趋于 y 2 ≠ 0 。 y^2 \ne 0\mathclose{\text{。}} y 2 = 0 。 对于 y = 0 : y = 0\mathclose{\text{:}} y = 0 : f ( h , 0 ) = 0 f(h, 0) = 0 f ( h , 0 ) = 0 对于每一个 h , h\mathclose{\text{,}} h , 因此 f x ( 0 , 0 ) = 0 = − 0 。 f_x(0, 0) = 0 = -0\mathclose{\text{。}} f x ( 0 , 0 ) = 0 = − 0 。 所以 f x ( 0 , y ) = − y f_x(0, y) = -y f x ( 0 , y ) = − y 对于每一个 y 。 y\mathclose{\text{。}} y 。 同样地,对于 x ≠ 0 , x \ne 0\mathclose{\text{,}} x = 0 , 由于 f ( x , 0 ) = 0 , f(x, 0) = 0\mathclose{\text{,}} f ( x , 0 ) = 0 ,
f y ( x , 0 ) = lim h → 0 f ( x , h ) h = lim h → 0 x ( x 2 − h 2 ) x 2 + h 2 = x , \begin{aligned} f_y(x, 0) &= \lim_{h\to0}\frac{f(x, h)}{h} \\ &= \lim_{h\to0}\frac{x(x^2 - h^2)}{x^2 + h^2} = x, \end{aligned} f y ( x , 0 ) = h → 0 lim h f ( x , h ) = h → 0 lim x 2 + h 2 x ( x 2 − h 2 ) = x ,
并且 f y ( 0 , 0 ) = 0 f_y(0, 0) = 0 f y ( 0 , 0 ) = 0 因为 f ( 0 , h ) = 0 。 f(0, h) = 0\mathclose{\text{。}} f ( 0 , h ) = 0 。 因此 f y ( x , 0 ) = x f_y(x, 0) = x f y ( x , 0 ) = x 对于每一个 x 。 x\mathclose{\text{。}} x 。
(b) f x y ( 0 , 0 ) f_{xy}(0, 0) f x y ( 0 , 0 ) 是 y ↦ f x ( 0 , y ) = − y y \mapsto f_x(0, y) = -y y ↦ f x ( 0 , y ) = − y 在 y = 0 y = 0 y = 0 处的导数,即 − 1 。 -1\mathclose{\text{。}} − 1 。 f y x ( 0 , 0 ) f_{yx}(0, 0) f y x ( 0 , 0 ) 是 x ↦ f y ( x , 0 ) = x x \mapsto f_y(x, 0) = x x ↦ f y ( x , 0 ) = x 在 x = 0 x = 0 x = 0 处的导数,即 1 。 1\mathclose{\text{。}} 1 。
(c) 克莱因定理需要 f x y f_{xy} f x y 和 f y x f_{yx} f y x 在原点附近的一个圆盘上连续。它们不能同时连续,否则定理会使它们在该区域相等。事实上,对于 ( x , y ) ≠ ( 0 , 0 ) , (x, y) \ne (0, 0)\mathclose{\text{,}} ( x , y ) = ( 0 , 0 ) , 规则给出
f x y = x 6 + 9 x 4 y 2 − 9 x 2 y 4 − y 6 ( x 2 + y 2 ) 3 , f_{xy} = \frac{x^6 + 9x^4y^2 - 9x^2y^4 - y^6}{(x^2 + y^2)^3}, f x y = ( x 2 + y 2 ) 3 x 6 + 9 x 4 y 2 − 9 x 2 y 4 − y 6 ,
该点在 x x x 轴上为 1,在 − 1 -1 − 1 轴上距离原点 y y y 的位置,因此在该点处无极限。函数本身是连续的:由于 ∣ x 2 − y 2 ∣ ≤ x 2 + y 2 , \abs{x^2 - y^2} \le x^2 + y^2\mathclose{\text{,}} x 2 − y 2 ≤ x 2 + y 2 , 它在原点处被 ∣ f ∣ ≤ ∣ x y ∣ → 0 \abs{f} \le \abs{xy} \to 0 ∣ f ∣ ≤ ∣ x y ∣ → 0 夹逼。它在所有点处都有一阶偏导数;混合偏导数的连续性是失败的假设。
练习 17.11 ★★★ 通过共享权重的反向传播
循环网络应用相同的步骤两次,使用相同的参数 w w w 和 b : b\mathclose{\text{:}} b : 从输入 x x x 计算 h 1 = w x + b , h_1 = wx + b\mathclose{\text{,}} h 1 = w x + b , 然后 h 2 = w h 1 + b , h_2 = wh_1 + b\mathclose{\text{,}} h 2 = w h 1 + b , 其损失为 L = ( h 2 − t ) 2 , L = (h_2 - t)^2\mathclose{\text{,}} L = ( h 2 − t ) 2 , 以目标 t t t 为基准。
(a) 画出计算图,并标出其局部导数。哪些节点有两个子节点?
(b) 使用 x = 1 、 x = 1\mathclose{\text{、}} x = 1 、 t = 5 、 t = 5\mathclose{\text{、}} t = 5 、 w = 2 w = 2 w = 2 和 b = 1 , b = 1\mathclose{\text{,}} b = 1 , 进行一次前向传播和一次反向传播,以求得 ∂ L / ∂ w \partial L/\partial w ∂ L / ∂ w 和 ∂ L / ∂ b 。 \partial L/\partial b\mathclose{\text{。}} ∂ L / ∂ b 。
(c) 通过将 L L L 表示为 w w w 和 b b b 的函数并求导来验证。
(d) 使用 η = 0.01 \eta = 0.01 η = 0.01 进行一次梯度下降步骤。损失是否减少?
查看解答✓ 已检验
(a) 节点是 w , w\mathclose{\text{,}} w , b , b\mathclose{\text{,}} b , h 1 = w x + b , h_1 = wx + b\mathclose{\text{,}} h 1 = w x + b , h 2 = w h 1 + b h_2 = wh_1 + b h 2 = w h 1 + b 和 L = ( h 2 − t ) 2 ; L = (h_2 - t)^2\mathclose{\text{;}} L = ( h 2 − t ) 2 ; 输入 x x x 和 目标 t t t 是 常量。箭头运行 w → h 1 w \to h_1 w → h 1 和 b → h 1 ; b \to h_1\mathclose{\text{;}} b → h 1 ; w → h 2 , w \to h_2\mathclose{\text{,}} w → h 2 , b → h 2 b \to h_2 b → h 2 和 h 1 → h 2 ; h_1 \to h_2\mathclose{\text{;}} h 1 → h 2 ; 和 h 2 → L 。 h_2 \to L\mathclose{\text{。}} h 2 → L 。 参数 w w w 和 b b b 每个都有两个子节点 h 1 h_1 h 1 和 h 2 , h_2\mathclose{\text{,}} h 2 , 因为它们在两个步骤中都被使用。局部导数是 ∂ h 1 / ∂ w = x , \partial h_1/\partial w = x\mathclose{\text{,}} ∂ h 1 / ∂ w = x , ∂ h 1 / ∂ b = 1 , \partial h_1/\partial b = 1\mathclose{\text{,}} ∂ h 1 / ∂ b = 1 , ∂ h 2 / ∂ w = h 1 , \partial h_2/\partial w = h_1\mathclose{\text{,}} ∂ h 2 / ∂ w = h 1 , ∂ h 2 / ∂ b = 1 , \partial h_2/\partial b = 1\mathclose{\text{,}} ∂ h 2 / ∂ b = 1 , ∂ h 2 / ∂ h 1 = w \partial h_2/\partial h_1 = w ∂ h 2 / ∂ h 1 = w 和 ∂ L / ∂ h 2 = 2 ( h 2 − t ) 。 \partial L/\partial h_2 = 2(h_2 - t)\mathclose{\text{。}} ∂ L / ∂ h 2 = 2 ( h 2 − t ) 。
(b) 前向: h 1 = 2 ⋅ 1 + 1 = 3 , h_1 = 2 \cdot 1 + 1 = 3\mathclose{\text{,}} h 1 = 2 ⋅ 1 + 1 = 3 , h 2 = 2 ⋅ 3 + 1 = 7 h_2 = 2 \cdot 3 + 1 = 7 h 2 = 2 ⋅ 3 + 1 = 7 和 L = ( 7 − 5 ) 2 = 4 。 L = (7 - 5)^2 = 4\mathclose{\text{。}} L = ( 7 − 5 ) 2 = 4 。 后向: L ˉ = 1 ; \bar L = 1\mathclose{\text{;}} L ˉ = 1 ; h ˉ 2 = L ˉ ⋅ 2 ( h 2 − t ) = 4 ; \bar h_2 = \bar L \cdot 2(h_2 - t) = 4\mathclose{\text{;}} h ˉ 2 = L ˉ ⋅ 2 ( h 2 − t ) = 4 ; h ˉ 1 = h ˉ 2 ⋅ w = 8 。 \bar h_1 = \bar h_2 \cdot w = 8\mathclose{\text{。}} h ˉ 1 = h ˉ 2 ⋅ w = 8 。 每个参数将其两个子节点的贡献相加:
w ˉ = h ˉ 2 ⋅ h 1 + h ˉ 1 ⋅ x = 4 ⋅ 3 + 8 ⋅ 1 = 20 , b ˉ = h ˉ 2 ⋅ 1 + h ˉ 1 ⋅ 1 = 4 + 8 = 12. \begin{aligned} \bar w &= \bar h_2 \cdot h_1 + \bar h_1 \cdot x = 4 \cdot 3 + 8 \cdot 1 = 20, \\ \bar b &= \bar h_2 \cdot 1 + \bar h_1 \cdot 1 = 4 + 8 = 12. \end{aligned} w ˉ b ˉ = h ˉ 2 ⋅ h 1 + h ˉ 1 ⋅ x = 4 ⋅ 3 + 8 ⋅ 1 = 20 , = h ˉ 2 ⋅ 1 + h ˉ 1 ⋅ 1 = 4 + 8 = 12.
所以 ∂ L / ∂ w = 20 \partial L/\partial w = 20 ∂ L / ∂ w = 20 和 ∂ L / ∂ b = 12 。 \partial L/\partial b = 12\mathclose{\text{。}} ∂ L / ∂ b = 12 。
(c) h 2 = w ( w x + b ) + b = w 2 x + w b + b , h_2 = w(wx + b) + b = w^2x + wb + b\mathclose{\text{,}} h 2 = w ( w x + b ) + b = w 2 x + w b + b , 所以 L = ( w 2 x + w b + b − t ) 2 , L = (w^2x + wb + b - t)^2\mathclose{\text{,}} L = ( w 2 x + w b + b − t ) 2 , 并且根据链式法则
L w = 2 ( h 2 − t ) ( 2 w x + b ) = 2 ⋅ 2 ⋅ 5 = 20 , L b = 2 ( h 2 − t ) ( w + 1 ) = 2 ⋅ 2 ⋅ 3 = 12. \begin{aligned} L_w &= 2(h_2 - t)(2wx + b) = 2 \cdot 2 \cdot 5 = 20, \\ L_b &= 2(h_2 - t)(w + 1) = 2 \cdot 2 \cdot 3 = 12. \end{aligned} L w L b = 2 ( h 2 − t ) ( 2 w x + b ) = 2 ⋅ 2 ⋅ 5 = 20 , = 2 ( h 2 − t ) ( w + 1 ) = 2 ⋅ 2 ⋅ 3 = 12.
(d) ⟨ w , b ⟩ = ⟨ 2 , 1 ⟩ − 0.01 ⟨ 20 , 12 ⟩ = ⟨ 1.8 , 0.88 ⟩ 。 \langle w, b\rangle = \langle 2, 1\rangle - 0.01\,\langle 20, 12\rangle = \langle 1.8, 0.88\rangle\mathclose{\text{。}} ⟨ w , b ⟩ = ⟨ 2 , 1 ⟩ − 0.01 ⟨ 20 , 12 ⟩ = ⟨ 1.8 , 0.88 ⟩ 。 然后 h 1 = 1.8 + 0.88 = 2.68 , h_1 = 1.8 + 0.88 = 2.68\mathclose{\text{,}} h 1 = 1.8 + 0.88 = 2.68 , h 2 = 1.8 ⋅ 2.68 + 0.88 = 5.704 , h_2 = 1.8 \cdot 2.68 + 0.88 = 5.704\mathclose{\text{,}} h 2 = 1.8 ⋅ 2.68 + 0.88 = 5.704 , 和 L = 0.704 2 ≈ 0.496 : L = 0.704^2 \approx 0.496\mathclose{\text{:}} L = 0.70 4 2 ≈ 0.496 : 损失值从 4 下降了。
1 f ( x , y ) = x 2 + 4 y 2 f(x, y) = x^2 + 4y^2 f ( x , y ) = x 2 + 4 y 2 的水平集,对于其值域中的值,是
以原点为中心的圆 抛物线 以原点为中心的椭圆,以及单点 ( 0 , 0 ) (0, 0) ( 0 , 0 ) 通过原点的直线 对于
k > 0 , k > 0\mathclose{\text{,}} k > 0 , x 2 + 4 y 2 = k x^2 + 4y^2 = k x 2 + 4 y 2 = k 是一个椭圆,它沿
x x x 轴达到
k , \sqrt k\mathclose{\text{,}} k , 但在
y y y 轴上仅达到
k / 2 ; \sqrt k/2\mathclose{\text{;}} k /2 ; 对于
k = 0 , k = 0\mathclose{\text{,}} k = 0 , 它仅包含原点。它们不是圆,因为两个半轴长度不同。两个平方项都有正系数,因此得到的是这些椭圆,而不是抛物线或直线。
2 对于
f ( x , y ) = x 2 y 3 , f(x, y) = x^2y^3\mathclose{\text{,}} f ( x , y ) = x 2 y 3 , f x f_x f x 是
2 x y 3 2xy^3 2 x y 3 3 x 2 y 2 3x^2y^2 3 x 2 y 2 2 x y 3 + 3 x 2 y 2 2xy^3 + 3x^2y^2 2 x y 3 + 3 x 2 y 2 6 x y 2 6xy^2 6 x y 2 固定
y : y\mathclose{\text{:}} y : y 3 y^3 y 3 是一个常数因子,
x 2 x^2 x 2 的导数是
2 x 。 2x\mathclose{\text{。}} 2 x 。 3 x 2 y 2 3x^2y^2 3 x 2 y 2 是
f y ; f_y\mathclose{\text{;}} f y ; 2 x y 3 + 3 x 2 y 2 2xy^3 + 3x^2y^2 2 x y 3 + 3 x 2 y 2 对两个变量同时求导;
6 x y 2 6xy^2 6 x y 2 是混合偏导数
f x y 。 f_{xy}\mathclose{\text{。}} f x y 。
3 沿着直线
y = 2 x , y = 2x\mathclose{\text{,}} y = 2 x , 带
x ≠ 0 , x \ne 0\mathclose{\text{,}} x = 0 , 函数
x y x 2 + y 2 \dfrac{xy}{x^2 + y^2} x 2 + y 2 x y 等于
1 2 \dfrac12 2 1 2 5 \dfrac25 5 2 0 0 0 2 2 2 x ⋅ 2 x x 2 + 4 x 2 = 2 x 2 5 x 2 = 2 5 . \dfrac{x \cdot 2x}{x^2 + 4x^2} = \dfrac{2x^2}{5x^2} = \dfrac25\mathclose{\text{.}} x 2 + 4 x 2 x ⋅ 2 x = 5 x 2 2 x 2 = 5 2 . 1 2 \tfrac12 2 1 是沿
y = x y = x y = x 的值,而 0 是沿坐标轴的值;由于不同的直线给出不同的值,函数在原点处没有极限。2 是直线的斜率,不是函数的值。
4 在
( 1 , 2 , 5 ) (1, 2, 5) ( 1 , 2 , 5 ) 处,曲面
z = x 2 + y 2 z = x^2 + y^2 z = x 2 + y 2 的切平面是
z = 2 x + 4 y z = 2x + 4y z = 2 x + 4 y z = 5 + 2 x + 4 y z = 5 + 2x + 4y z = 5 + 2 x + 4 y z = 5 + 2 x ( x − 1 ) + 2 y ( y − 2 ) z = 5 + 2x(x - 1) + 2y(y - 2) z = 5 + 2 x ( x − 1 ) + 2 y ( y − 2 ) z = 5 + 2 ( x − 1 ) + 4 ( y − 2 ) z = 5 + 2(x - 1) + 4(y - 2) z = 5 + 2 ( x − 1 ) + 4 ( y − 2 ) f x = 2 x f_x = 2x f x = 2 x 和
f y = 2 y f_y = 2y f y = 2 y 在
( 1 , 2 ) (1, 2) ( 1 , 2 ) 处分别为 2 和 4,因此平面是
z = f ( 1 , 2 ) + 2 ( x − 1 ) + 4 ( y − 2 ) 。 z = f(1, 2) + 2(x - 1) + 4(y - 2)\mathclose{\text{。}} z = f ( 1 , 2 ) + 2 ( x − 1 ) + 4 ( y − 2 ) 。 z = 2 x + 4 y z = 2x + 4y z = 2 x + 4 y 的斜率正确,但在
( 1 , 2 ) (1, 2) ( 1 , 2 ) 处高度为 10,不是 5;
z = 5 + 2 x + 4 y z = 5 + 2x + 4y z = 5 + 2 x + 4 y 忘记了减去
a a a 和
b ; b\mathclose{\text{;}} b ; 第三个保持了
f x = 2 x f_x = 2x f x = 2 x 和
f y = 2 y , f_y = 2y\mathclose{\text{,}} f y = 2 y , 但未在该点进行计算,因此不是一个平面。
5 f f f 在
∇ f = ⟨ 3 , − 4 ⟩ \nabla f = \langle 3, -4\rangle ∇ f = ⟨ 3 , − 4 ⟩ 处可微。哪一项是正确的?
那里的最大方向导数是 7。 f f f 在 ⟨ − 3 , 4 ⟩ / 5 \langle -3, 4\rangle/5 ⟨ − 3 , 4 ⟩ /5 方向增长最快。那里的最大方向导数是 5,方向为 ⟨ 3 , − 4 ⟩ / 5 。 \langle 3, -4\rangle/5\mathclose{\text{。}} ⟨ 3 , − 4 ⟩ /5 。 D u f = 0 D_{\vb{u}} f = 0 D u f = 0 对 u = ⟨ 3 , − 4 ⟩ / 5 。 \vb{u} = \langle 3, -4\rangle/5\mathclose{\text{。}} u = ⟨ 3 , − 4 ⟩ /5 。 最大速率为
∥ ∇ f ∥ = 9 + 16 = 5 , \norm{\nabla f} = \sqrt{9 + 16} = 5\mathclose{\text{,}} ∥ ∇ f ∥ = 9 + 16 = 5 , 方向为
∇ f \nabla f ∇ f (定理17.10)。7将各分量的大小相加而非取长度;
⟨ − 3 , 4 ⟩ / 5 \langle -3, 4\rangle/5 ⟨ − 3 , 4 ⟩ /5 是最快减少的方向;而在与
∇ f \nabla f ∇ f 垂直的方向
± ⟨ 4 , 3 ⟩ / 5 \pm\langle 4, 3\rangle/5 ± ⟨ 4 , 3 ⟩ /5 上,速率为0,而非沿其方向。
6 克莱罗定理说明当
f x y ( a , b ) = f y x ( a , b ) f_{xy}(a, b) = f_{yx}(a, b) f x y ( a , b ) = f y x ( a , b ) 满足
f x y f_{xy} f x y 和 f y x f_{yx} f y x 在以 ( a , b ) (a, b) ( a , b ) 为中心的开圆盘上连续f x f_x f x 和 f y f_y f y 在 ( a , b ) (a, b) ( a , b ) 处存在f f f 在 ( a , b ) (a, b) ( a , b ) 处连续没有更多要求:它对所有函数都成立 假设是混合偏导数在该点附近连续。
f x f_x f x 和
f y f_y f y 的存在,以及
f f f 的连续性,并不足以保证结论成立:练习 17.10 中的函数是连续的,在所有点都有两个一阶偏导数,并且有
f x y ( 0 , 0 ) = − 1 f_{xy}(0, 0) = -1 f x y ( 0 , 0 ) = − 1 但没有
f y x ( 0 , 0 ) = 1 。 f_{yx}(0, 0) = 1\mathclose{\text{。}} f y x ( 0 , 0 ) = 1 。
7 从
( 1 , 2 ) (1, 2) ( 1 , 2 ) 出发,以
η = 0.25 \eta = 0.25 η = 0.25 为步长进行一次梯度下降在
f ( x , y ) = x 2 + y 2 f(x, y) = x^2 + y^2 f ( x , y ) = x 2 + y 2 上得到
( 1.5 , 3 ) (1.5, 3) ( 1.5 , 3 ) ( 0.5 , 1 ) (0.5, 1) ( 0.5 , 1 ) ( 0.75 , 1.75 ) (0.75, 1.75) ( 0.75 , 1.75 ) ( 0 , 0 ) (0, 0) ( 0 , 0 ) ∇ f ( 1 , 2 ) = ⟨ 2 , 4 ⟩ , \nabla f(1, 2) = \langle 2, 4\rangle\mathclose{\text{,}} ∇ f ( 1 , 2 ) = ⟨ 2 , 4 ⟩ , 所以新的点是
( 1 , 2 ) − 0.25 ⟨ 2 , 4 ⟩ = ( 0.5 , 1 ) 。 (1, 2) - 0.25\,\langle 2, 4\rangle = (0.5, 1)\mathclose{\text{。}} ( 1 , 2 ) − 0.25 ⟨ 2 , 4 ⟩ = ( 0.5 , 1 ) 。 ( 1.5 , 3 ) (1.5, 3) ( 1.5 , 3 ) 添加
η ∇ f \eta\nabla f η ∇ f 并向上爬;
( 0.75 , 1.75 ) (0.75, 1.75) ( 0.75 , 1.75 ) 减去
η \eta η 本身而不是
η ∇ f ; \eta\nabla f\mathclose{\text{;}} η ∇ f ; ( 0 , 0 ) , (0, 0)\mathclose{\text{,}} ( 0 , 0 ) , 即最小值,是用
η = 0.5 \eta = 0.5 η = 0.5 一步就能到达的地方。
8 在反向传播中,一个值被两个后续节点
c 1 c_1 c 1 和
c 2 c_2 c 2 使用的节点
v v v 会获得对应的共轭量
c ˉ 1 ∂ c 1 ∂ v ⋅ c ˉ 2 ∂ c 2 ∂ v \bar c_1\,\dfrac{\partial c_1}{\partial v}\cdot\bar c_2\,\dfrac{\partial c_2}{\partial v} c ˉ 1 ∂ v ∂ c 1 ⋅ c ˉ 2 ∂ v ∂ c 2 c ˉ 1 \bar c_1 c ˉ 1 和 c ˉ 2 \bar c_2 c ˉ 2 中较大的那个c ˉ 1 ∂ c 1 ∂ v \bar c_1\,\dfrac{\partial c_1}{\partial v} c ˉ 1 ∂ v ∂ c 1 仅来自两个子节点中的第一个c ˉ 1 ∂ c 1 ∂ v + c ˉ 2 ∂ c 2 ∂ v \bar c_1\,\dfrac{\partial c_1}{\partial v} + \bar c_2\,\dfrac{\partial c_2}{\partial v} c ˉ 1 ∂ v ∂ c 1 + c ˉ 2 ∂ v ∂ c 2 L L L 通过
c 1 c_1 c 1 和
c 2 c_2 c 2 两个路径依赖于
v , v\mathclose{\text{,}} v , 链式法则为每个路径添加一项,如同树状图所示。相乘两个项、取较大共轭量或仅保留一项都会丢失部分依赖关系。
重新作答