Ran Wei/ 微积分/模块 4
English
微积分 · 第二部分 · 导数

模块 4导数

从模块 1 的平均变化率过渡到瞬时变化率。你将用极限定义导数,理解导数与切线斜率、速度的关系,再证明基本求导法则。用 SymPy 作精确计算,并比较数值求导在小步长下受到的浮点误差。

⏱ 255 分钟开始之前:模块 1, 2 和 3

在本模块中,你将

  • 从极限定义计算导数,并写出切线方程
  • 将导数解释为斜率、速度和变化率,并标明其单位
  • 从 f 的图像绘制 f′ 的图像,并识别函数无导数的点
  • 证明幂函数、常数倍和和法则,并利用它们对多项式求导
  • 求高阶导数,以及运动物体的速度、加速度和冲击加速度
  • 数值估计导数,并选择一个平衡截断误差和舍入误差的步长
1

切线与速度

在模块 1 中你掉了一个球。经过 tt 秒后,它下落了 s(t)=4.9t2s(t) = 4.9t^2 米,且从 t=1t = 1 到 t=1+ht = 1 + h 之间的平均速度是

s(1+h)−s(1)h=9.8+4.9h(h≠0),\frac{s(1 + h) - s(1)}{h} = 9.8 + 4.9h \qquad (h \ne 0),

如 例 1.12] 所示。当 hh 从两侧趋近于 0 时,这些平均值趋于 9.8 m/s。模块 2 给出了这个趋近的精确含义,即极限,并求出了球在任意时刻 aa 的速度,而不仅是在 t=1t = 1 时的速度:

lim⁡h→0s(a+h)−s(a)h=lim⁡h→0 (9.8a+4.9h)=9.8a m/s.\begin{aligned} \lim_{h\to0}\frac{s(a + h) - s(a)}{h} &= \lim_{h\to0}\,(9.8a + 4.9h) \\ &= 9.8a \text{ m/s}. \end{aligned}

商等于 9.8a+4.9h9.8a + 4.9h 对于每一个 h≠0h \ne 0 都成立,且极限作为 h→0h \to 0 从不使用 h=0h = 0 自身的值;因此直接代入得到 9.8a。9.8a\mathclose{\text{。}}所以球在第一秒后下落速度为 9.8 m/s,在第二秒后为 19.6 m/s。这个极限就是球上速度表所显示的数值。

定义 4.1瞬时速度

假设一个物体沿一条直线运动,且 s(t)s(t) 是它在时间 tt 时的位置,从固定点测量。它在时间 aa 时的 瞬时速度,或简称为 速度,为

v(a)=lim⁡h→0s(a+h)−s(a)h,v(a) = \lim_{h\to0}\frac{s(a + h) - s(a)}{h},

该极限存在的前提下。它在时间 aa 时的 速度 为 ∣v(a)∣。\abs{v(a)}\mathclose{\text{。}}

速度有正负号:正速度表示物体沿正方向运动,负速度表示物体沿相反方向运动。速度忽略方向。对于向下测量距离的下落球来说,两者是相同的。

例 4.1刹车的汽车✓ 已检验

假设一辆车匀速刹车,刹车开始后 tt 秒,车已行驶 s(t)=20t−2t2s(t) = 20t - 2t^2 米。(数字是虚构的。)求 aa 时刻的瞬时速度,以及速度表在 t=0t = 0 和 t=2t = 2 时显示的数值,以及车何时、何处停止。

将 a+ha + h 代入 t,t\mathclose{\text{,}}保持括号,展开,并使用 (a+h)2=a2+2ah+h2:(a + h)^2 = a^2 + 2ah + h^2\mathclose{\text{:}}

s(a+h)=20(a+h)−2(a+h)2=20a+20h−2(a2+2ah+h2)=20a+20h−2a2−4ah−2h2.\begin{aligned} &s(a + h) \\ &\quad= 20(a + h) - 2(a + h)^2 \\ &\quad= 20a + 20h - 2(a^2 + 2ah + h^2) \\ &\quad= 20a + 20h - 2a^2 - 4ah - 2h^2. \end{aligned}

减去 s(a)=20a−2a2:s(a) = 20a - 2a^2\mathclose{\text{:}}项 20a20a 和 −2a2-2a^2 抵消,剩下 s(a+h)−s(a)=20h−4ah−2h2。s(a + h) - s(a) = 20h - 4ah - 2h^2\mathclose{\text{。}}每个剩余项都包含 h,h\mathclose{\text{,}}因此除以 hh(允许,因为 h≠0),h \ne 0\mathclose{\text{),}}然后令 h→0:h \to 0\mathclose{\text{:}}

v(a)=lim⁡h→020h−4ah−2h2h=lim⁡h→0 (20−4a−2h)=20−4a m/s.\begin{aligned} v(a) &= \lim_{h\to0}\frac{20h - 4ah - 2h^2}{h} \\ &= \lim_{h\to0}\,(20 - 4a - 2h) \\ &= 20 - 4a \text{ m/s}. \end{aligned}

在 t=0t = 0 时,速度表显示 20 m/s,即 72 km/h(将 m/s 乘以 3.6 得到 km/h);在 t=2t = 2 时显示 20−8=1220 - 8 = 12 m/s。速度每秒减少 4 m/s,当 20−4a=020 - 4a = 0 时速度降为 0,此时已过 t=5t = 5 秒。到那时,车已行驶 s(5)=100−50=50s(5) = 100 - 50 = 50 米。该公式仅适用于 0≤t≤5:0 \le t \le 5\mathclose{\text{:}}在 t=5t = 5 之后,车将反向行驶,而刹车不会这样做。

切线

模块 1 描述了曲线在点 PP 处的切线,作为通过 PP 的割线在第二点 QQ 滑动靠近 PP 时所趋近的直线(图 1.5 展示了球的情况)。通过 P=(a,f(a))P = (a, f(a)) 和 Q=(a+h,f(a+h))Q = (a + h, f(a + h)) 的割线的斜率是差商,因此切线的斜率是差商的极限:与速度相同的极限。

定义 4.2切线

设 ff 在包含 aa 的开区间上定义,且 P=(a,f(a))。P = (a, f(a))\mathclose{\text{。}}如果极限

m=lim⁡h→0f(a+h)−f(a)hm = \lim_{h\to0}\frac{f(a + h) - f(a)}{h}

存在,函数 ff 在点 PP 处的 切线 是经过点 PP 且斜率为 mm 的直线。根据 第 1.4 节 的点斜式,其方程为

y=f(a)+m(x−a).y = f(a) + m(x - a).

开区间确保 f(a+h)f(a + h) 在每一个小的 hh(正或负)都有定义,因此割线可以从两侧趋近。

例 4.2曲线 y=x3y = x^3 在 (1,1)(1, 1) 处的切线✓ 已检验

求曲线 y=x3y = x^3 在点 (1,1)(1, 1) 处的切线,并找出它在曲线上的其他交点。

在练习 1.8 中你展开 (1+h)3=1+3h+3h2+h3(1 + h)^3 = 1 + 3h + 3h^2 + h^3 并发现,对于 h≠0,h \ne 0\mathclose{\text{,}}

(1+h)3−1h=3h+3h2+h3h=3+3h+h2.\begin{aligned} \frac{(1 + h)^3 - 1}{h} &= \frac{3h + 3h^2 + h^3}{h} \\ &= 3 + 3h + h^2. \end{aligned}

该表显示了 PP 两侧的割线斜率:

hh(1+h)3−1h\dfrac{(1+h)^3 - 1}{h}
0.10.13.313.31
0.010.013.03013.0301
0.0010.0013.0030013.003001
−0.001-0.0012.9970012.997001
−0.01-0.012.97012.9701
−0.1-0.12.712.71

它们趋近于 3,当 h>0h > 0 时从上方趋近,当 h<0h < 0 时从下方趋近。直接代入得到 m=lim⁡h→0(3+3h+h2)=3,m = \lim_{h\to0}(3 + 3h + h^2) = 3\mathclose{\text{,}}因此切线为 y=1+3(x−1),y = 1 + 3(x - 1)\mathclose{\text{,}}即,

y=3x−2.y = 3x - 2.

它与曲线相交于 x3=3x−2,x^3 = 3x - 2\mathclose{\text{,}}即 x3−3x+2=0x^3 - 3x + 2 = 0 处。由于 x=1x = 1 是一个解,因此 x−1x - 1 是一个因子(模块 2)。为找到另一个因子,将 −3x+2-3x + 2 写成 −x−(2x−2)-x - (2x - 2) 并分组:

x3−3x+2=(x3−x)−(2x−2)=x(x−1)(x+1)−2(x−1)=(x−1)(x2+x−2)=(x−1)2(x+2),\begin{aligned} &x^3 - 3x + 2 \\ &\quad= (x^3 - x) - (2x - 2) \\ &\quad= x(x - 1)(x + 1) - 2(x - 1) \\ &\quad= (x - 1)(x^2 + x - 2) \\ &\quad= (x - 1)^2(x + 2), \end{aligned}

其中最后一步将 x2+x−2=(x−1)(x+2)x^2 + x - 2 = (x - 1)(x + 2) 因式分解。因此,直线再次与曲线相交于 x=−2,x = -2\mathclose{\text{,}}在点 (−2,−8)(-2, -8) 处。重复因子 (x−1)2(x - 1)^2 是切线的代数标志:直线在 x=1x = 1 处“两次”相交。

注意

“一条切线只在曲线上一点接触。” 这对圆来说是对的,但不是普遍情况:例4.2中的切线在 (−2,−8)(-2, -8) 处再次穿过 y=x3。y = x^3\mathclose{\text{。}}而且一条只与曲线相交一次的直线未必是切线:垂直线 x=1x = 1 仅在 (1,1)(1, 1) 处与 y=x3y = x^3 相交。使一条直线成为 PP 点的切线的是它的斜率,即割线斜率的极限。

放大切点,你就会明白为什么这条直线被称为切线。图4.1将 y=x3y = x^3 在 (1,1)(1, 1) 附近的图像放大了十倍,然后再放大十倍。在第一个窗口中,曲线偏离其切线,第二个窗口中偏离程度更小,第三个窗口中两者无法分辨。在切点附近,曲线看起来是直的,它看起来像的那条直线就是切线。

放大 y = x^3(蓝色)在 (1, 1) 点处,其切线为 y = 3x - 2(虚线)。每个方框标记下一个面板的窗口,每个方向缩小十倍。在最后一个窗口(宽0.03)中,曲线和切线看起来一模一样。
图 4.1

放大 y=x3y = x^3(蓝色)在 (1,1)(1, 1) 点处,其切线为 y=3x−2y = 3x - 2(虚线)。每个方框标记下一个面板的窗口,每个方向缩小十倍。在最后一个窗口(宽0.03)中,曲线和切线看起来一模一样。

2

导数

速度和切线的斜率是同一个极限。其他任何瞬时变化率也是如此:水从水箱中流出的速度,以升每秒为单位;一杯茶冷却的速度,以度每分钟为单位;机器学习模型的误差随其参数变化的速度。这个极限有其自己的名称。

定义 4.3某点的导数

设 ff 在包含 aa 的开区间上定义。函数 ff 在 aa处的导数为

f′(a)=lim⁡h→0f(a+h)−f(a)h,f'(a) = \lim_{h\to0}\frac{f(a + h) - f(a)}{h},

假设这个极限存在(作为一个实数)。那么 ff 是 在 aa 处可导。符号 f′(a)f'(a) 表示 “a 的导数 f’”。

将 x=a+hx = a + h 代入可得到第二种形式,通常更方便:

f′(a)=lim⁡x→af(x)−f(a)x−a.f'(a) = \lim_{x\to a}\frac{f(x) - f(a)}{x - a}.

这两种形式表达的是同一个意思。对于每一个 x≠a,x \ne a\mathclose{\text{,}}第二种形式在 xx 处的商等于定义形式在 h=x−ah = x - a 处的商;且 ∣x−a∣<δ\abs{x - a} < \delta 与 ∣h∣<δ\abs{h} < \delta 是相同的条件,因此根据模块 2 中的 ε–δ 定义,一个极限存在当且仅当另一个极限存在,且值相同。

以此名称,三个概念合而为一。

要点

导数 f′(a)f'(a) 是

  • 曲线 y=f(x)y = f(x) 在点 (a,f(a))(a, f(a)) 处切线的 斜率,即 y=f(a)+f′(a)(x−a);y = f(a) + f'(a)(x - a)\mathclose{\text{;}}
  • 函数 ff 在点 aa 处的 瞬时变化率,单位为 ff 每 x;x\mathclose{\text{;}}
  • 时间 aa 时的 速度,此时 f(t)f(t) 是运动物体在时间 tt 时的位置。
例 4.3由定义求导✓ 已检验

设 f(x)=2x2−5x+1。f(x) = 2x^2 - 5x + 1\mathclose{\text{。}}求 f′(2)f'(2) 以及图象在 x=2x = 2 处的切线。

首先, f(2)=8−10+1=−1。f(2) = 8 - 10 + 1 = -1\mathclose{\text{。}}接着代入 2+h,2 + h\mathclose{\text{,}}保持括号,展开,用 (2+h)2=4+4h+h2:(2 + h)^2 = 4 + 4h + h^2\mathclose{\text{:}}

f(2+h)=2(2+h)2−5(2+h)+1=2(4+4h+h2)−10−5h+1=8+8h+2h2−10−5h+1=−1+3h+2h2.\begin{aligned} &f(2 + h) \\ &\quad= 2(2 + h)^2 - 5(2 + h) + 1 \\ &\quad= 2(4 + 4h + h^2) - 10 - 5h + 1 \\ &\quad= 8 + 8h + 2h^2 - 10 - 5h + 1 \\ &\quad= -1 + 3h + 2h^2. \end{aligned}

所以 f(2+h)−f(2)=3h+2h2,f(2 + h) - f(2) = 3h + 2h^2\mathclose{\text{,}}且

f′(2)=lim⁡h→03h+2h2h=lim⁡h→0 (3+2h)=3.\begin{aligned} f'(2) &= \lim_{h\to0}\frac{3h + 2h^2}{h} \\ &= \lim_{h\to0}\,(3 + 2h) = 3. \end{aligned}

切线为 y=−1+3(x−2),y = -1 + 3(x - 2)\mathclose{\text{,}}即 y=3x−7。y = 3x - 7\mathclose{\text{。}}检查是否经过该点:当 x=2x = 2 时,结果为 6−7=−1=f(2)。6 - 7 = -1 = f(2)\mathclose{\text{。}}

动手试试

从f(x)=x2f(x) = x^2和a=1a = 1开始;∣h∣\abs{h}的滑块在对数刻度上运行,从1递减至0.001。紫色直线是过(a,f(a))(a, f(a))和(a+h,f(a+h))(a + h, f(a + h))的割线;橙色虚线是aa处的切线。反复按Halve h,观察割线趋近切线,且差商趋近f′(1)=2:f'(1) = 2\mathclose{\text{:}}对于x2,x^2\mathclose{\text{,}}商为2a+h,2a + h\mathclose{\text{,}}因此每次减半使差距减半。切换hh的符号以查看来自左侧的割线。然后尝试x\sqrt x在a=0a = 0处,此时商无界增长,并输入|x|与a=0,a = 0\mathclose{\text{,}}此时两侧不一致(第4.4节)。对于sin⁡x\sin x和ex,e^x\mathclose{\text{,}}小部件从模块5和6证明的公式中获取f′(a);f'(a)\mathclose{\text{;}}对于你输入的函数,它数值估计f′(a),f'(a)\mathclose{\text{,}}正如第4.7节所解释的那样。

例 4.4从定义出发的两个更多导数✓ 已检验

求 (a) f′(2)f'(2) 在 f(x)=1xf(x) = \dfrac1x 处的值,使用第二种形式;并求 (b) g′(4)g'(4) 在 g(x)=xg(x) = \sqrt x 处的值,使用第一种形式。每种情况给出切线方程。

(a) 将分数合并,公分母为 2x:2x\mathclose{\text{:}}

f(x)−f(2)=1x−12=2−x2x=−x−22x.\begin{aligned} f(x) - f(2) &= \frac1x - \frac12 = \frac{2 - x}{2x} \\ &= -\frac{x - 2}{2x}. \end{aligned}

用 x−2x - 2 除(允许,因为 x≠2x \ne 2 在极限内),然后令 x→2:x \to 2\mathclose{\text{:}}

f′(2)=lim⁡x→2(−12x)=−14.f'(2) = \lim_{x\to2}\left(-\frac{1}{2x}\right) = -\frac14.

切线方程为 y=12−14(x−2),y = \tfrac12 - \tfrac14(x - 2)\mathclose{\text{,}}即 y=1−x4。y = 1 - \tfrac{x}{4}\mathclose{\text{。}}斜率为负,因为 1/x1/x 减小;练习 1.9 得到相同数值 −1/a2-1/a^2 在 a=2a = 2 处,使用第一种形式。

(b) 将 h=0h = 0 代入商 4+h−2h\dfrac{\sqrt{4 + h} - 2}{h} 得到 00,\tfrac00\mathclose{\text{,}}商中包含平方根,因此需要有理化,如模块 2 所示:将分子和分母同时乘以 4+h+2,\sqrt{4 + h} + 2\mathclose{\text{,}}对分子使用 (p−q)(p+q)=p2−q2,(p - q)(p + q) = p^2 - q^2\mathclose{\text{,}}并约去因子 hh(允许,因为 h≠0):h \ne 0\mathclose{\text{):}}

4+h−2h=(4+h)−4h(4+h+2)=14+h+2.\begin{aligned} \frac{\sqrt{4 + h} - 2}{h} &= \frac{(4 + h) - 4}{h\big(\sqrt{4 + h} + 2\big)} \\ &= \frac{1}{\sqrt{4 + h} + 2}. \end{aligned}

平方根在 4 处连续(模块 3),因此 4+h→2\sqrt{4 + h} \to 2 作为 h→0,h \to 0\mathclose{\text{,}}并 g′(4)=12+2=14。g'(4) = \dfrac{1}{2 + 2} = \dfrac14\mathclose{\text{。}}切线是 y=2+14(x−4),y = 2 + \tfrac14(x - 4)\mathclose{\text{,}}即 y=1+x4。y = 1 + \tfrac{x}{4}\mathclose{\text{。}}在 x=4x = 4 附近,它是曲线的良好替代:在 x=4.1x = 4.1 处,它给出 2.025,而 4.1≈2.0248。\sqrt{4.1} \approx 2.0248\mathclose{\text{。}}模块 7 将这一观察转化为一种方法,即线性近似。

注意

从定义出发求导时的两个错误。第一,继续书写 “lim⁡\lim” 直到让 h→0h \to 0 的步骤: 3h+2h2h=3+2h\dfrac{3h + 2h^2}{h} = 3 + 2h 对于 h≠0h \ne 0 是正确的,但它不是 3;它的极限是 3。第二,不要在约分前将 h=0h = 0 放入商中:这会得到 00,\tfrac00\mathclose{\text{,}}这不是一个数。首先约去因子 hh(允许这样做,因为 h≠0),h \ne 0\mathclose{\text{),}}然后让 h→0。h \to 0\mathclose{\text{。}}

3

导数作为函数

模块 2 和例 4.1 同时找到了每个时刻的速度: 9.8a9.8a 对于球, 20−4a20 - 4a 对于汽车。让点变化将导数转化为一个新的函数。

定义 4.4导数函数

ff 的导数是由下式给出的函数 f′:f'\mathclose{\text{:}}

f′(x)=lim⁡h→0f(x+h)−f(x)hf'(x) = \lim_{h\to0}\frac{f(x + h) - f(x)}{h}

在每一个 xx 处,只要 ff 可导,即在该点此极限按定义 4.3 的意义存在。其定义域是那些 xx 的集合,可能比 ff 的定义域更小。求 f′f' 的过程称为 求导 f。f\mathclose{\text{。}}

在极限中, xx 保持不变,而 hh 变动。

例 4.5x2x^2 和 x\sqrt x 的导数✓ 已检验

求 f′(x)f'(x) 对 f(x)=x2f(x) = x^2 的导数,以及 g′(x)g'(x) 对 g(x)=xg(x) = \sqrt x 的导数,并写出它们的定义域。

对于 f:f\mathclose{\text{:}} (x+h)2−x2=(x2+2xh+h2)−x2=2xh+h2,(x + h)^2 - x^2 = (x^2 + 2xh + h^2) - x^2 = 2xh + h^2\mathclose{\text{,}}因此对于 h≠0,h \ne 0\mathclose{\text{,}}差商是 2xh+h2h=2x+h,\dfrac{2xh + h^2}{h} = 2x + h\mathclose{\text{,}}并且 f′(x)=lim⁡h→0(2x+h)=2xf'(x) = \lim_{h\to0}(2x + h) = 2x 对于每一个实数 xx 都存在。

对于 g,g\mathclose{\text{,}}如例 4.4 所示进行有理化:对于 x>0x > 0(且 h≠0h \ne 0 足够小使得 x+h>0),x + h > 0\mathclose{\text{),}}

x+h−xh=(x+h)−xh(x+h+x)=1x+h+x.\begin{aligned} \frac{\sqrt{x + h} - \sqrt x}{h} &= \frac{(x + h) - x}{h\big(\sqrt{x + h} + \sqrt x\big)} \\ &= \frac{1}{\sqrt{x + h} + \sqrt x}. \end{aligned}

作为 h→0,h \to 0\mathclose{\text{,}} x+h→x,\sqrt{x + h} \to \sqrt x\mathclose{\text{,}} 因为平方根是连续的,所以 g′(x)=1x+x=12xg'(x) = \dfrac{1}{\sqrt x + \sqrt x} = \dfrac{1}{2\sqrt x} 对于 x>0。x > 0\mathclose{\text{。}} (在 x=4x = 4 这里得到 14,\tfrac14\mathclose{\text{,}}如前所述。) 在 x=0x = 0 处定义不适用,因为 x\sqrt x 在 0 的左侧未定义;而且即使从右侧来看,商 h−0h=1h\dfrac{\sqrt h - 0}{h} = \dfrac{1}{\sqrt h} 也会随着 h→0+h \to 0^+ 无限增大。因此 gg 的定义域是 [0,∞),[0, \infty)\mathclose{\text{,}}但 g′g' 的定义域是 (0,∞):(0, \infty)\mathclose{\text{:}}函数 x\sqrt x 的图像从原点开始垂直向上。

阅读 f′f' 的图像

f′f' 的图像在 xx 处的高度是 ff 的图像在 xx 处的斜率。这句话让你可以根据 ff 的图像直接绘制 f′,f'\mathclose{\text{,}}而不需要公式。图 4.2 显示了 f(x)=x3−3xf(x) = x^3 - 3x 及其在五个点处的切线,下方是其导函数的图像:下图中的每个点记录了上方切线的斜率。

顶:f(x) = x^3 - 3x 与其在 x = -2, -1, 0, 1, 2 处的切线。底:其导数 f'(x) = 3x^2 - 3;点表示这五条切线的斜率(9,0,-3,0,9)。当切线水平时,在 x = pm1(虚线)处,f' 为零;当 f 上升时,f' 为正;当 f 下降时,f' 为负。
图 4.2

顶:f(x)=x3−3xf(x) = x^3 - 3x 与其在 x=−2,−1,0,1,2x = -2, -1, 0, 1, 2 处的切线。底:其导数 f′(x)=3x2−3;f'(x) = 3x^2 - 3\mathclose{\text{;}}点表示这五条切线的斜率(9,0,−3,-3\mathclose{\text{,}}0,9)。当切线水平时,在 x=±1x = \pm1(虚线)处,f′f' 为零;当 ff 上升时,f′f' 为正;当 ff 下降时,f′f' 为负。

例 4.6阅读图 4.2✓ 已检验

对于 f(x)=x3−3x,f(x) = x^3 - 3x\mathclose{\text{,}}根据定义找出 f′(x),f'(x)\mathclose{\text{,}}并与 ff 的图像进行比较。

展开 (x+h)3=x3+3x2h+3xh2+h3(x + h)^3 = x^3 + 3x^2h + 3xh^2 + h^3(将 x2+2xh+h2x^2 + 2xh + h^2 乘以 x+hx + h 并合并同类项)。然后

f(x+h)−f(x)=[(x+h)3−x3]−3[(x+h)−x]=3x2h+3xh2+h3−3h,\begin{aligned} &f(x + h) - f(x) \\ &\quad= \big[(x + h)^3 - x^3\big] - 3\big[(x + h) - x\big] \\ &\quad= 3x^2h + 3xh^2 + h^3 - 3h, \end{aligned}

因此,差商为 3x2+3xh+h2−33x^2 + 3xh + h^2 - 3 在 h≠0h \ne 0 处,且

f′(x)=lim⁡h→0(3x2+3xh+h2−3)=3x2−3.\begin{aligned} f'(x) &= \lim_{h\to0}\big(3x^2 + 3xh + h^2 - 3\big) \\ &= 3x^2 - 3. \end{aligned}

现在与顶部图像进行比较。

  • ff 的图像在其峰值 (−1,2)(-1, 2) 和谷值 (1,−2)(1, -2) 处有水平切线。确实,当 x=±1x = \pm1 时,f′(x)=3x2−3=0f'(x) = 3x^2 - 3 = 0 恰好为零。
  • 在 −1-1 左侧和 1 右侧,图像上升,且 f′(x)=3(x2−1)>0,f'(x) = 3(x^2 - 1) > 0\mathclose{\text{,}}因为 x2>1。x^2 > 1\mathclose{\text{。}}
  • 在 −1-1 和 1 之间,图像下降,且 f′(x)<0。f'(x) < 0\mathclose{\text{。}}它在 x=0x = 0 处下降最陡,此时 f′(0)=−3f'(0) = -3 是 f′f' 的最小值。
  • 关于原点的一次旋转使 ff 的图像保持不变(ff 是奇函数),因此它将 xx 处的点映射到 −x-x 处的点,并将该处的切线映射到 −x-x 处的切线。一次旋转将每条直线变为一条平行直线,因此这两条切线的斜率相同: f′f' 是偶函数, f′(−x)=f′(x)。f'(-x) = f'(x)\mathclose{\text{。}}

这种读法适用于任何图像。

要点

从 ff 的图像来绘制 f′:f'\mathclose{\text{:}}

  • 当 ff 的切线水平(在峰值、谷值和某些平坦点)时, f′=0:f' = 0\mathclose{\text{:}} f′f' 的图像与 xx 轴相交;
  • 当 ff 上升时, f′≥0;f' \ge 0\mathclose{\text{;}}当 ff 下降时, f′≤0;f' \le 0\mathclose{\text{;}}
  • ff 越陡, f′f' 的图像离 xx 轴越远;
  • 其中 ff 有拐点、尖点、垂直切线或跳跃间断点,f′f' 未定义(第4.4节)。

第二条规则可从定义推出。若区间内凡有 x1<x2x_1 < x_2 总有 f(x1)<f(x2),f(x_1) < f(x_2)\mathclose{\text{,}}就称 ff 在该区间上递增(严格递增,见练习 1.10);若总有 f(x1)>f(x2),f(x_1) > f(x_2)\mathclose{\text{,}}则称递减。设 ff 在含 xx 的开区间上递增,并且在 xx 处可微。对每个足够小、使 x+hx + h 仍在该区间内的 h≠0,h \ne 0\mathclose{\text{,}}分子 f(x+h)−f(x)f(x + h) - f(x) 与 hh 同号,所以这些差商全为正。它们的极限 f′(x)f'(x) 不能为负,因为如果为负,当 hh 足够小时,差商与该极限的距离小于 ∣f′(x)∣/2,\abs{f'(x)}/2\mathclose{\text{,}}于是差商本身也为负。不过极限可以为 0:x3x^3 递增,但在 0 处切线水平。同理,ff 递减时 f′(x)≤0。f'(x) \le 0\mathclose{\text{。}}部分逆命题也成立:若区间内每一点都有 f′>0,f' > 0\mathclose{\text{,}}则 ff 在该区间递增。这需要模块 8 的微分中值定理来证明。

注意

图形 f′f' 记录的是斜率,而不是高度。在 ff 的顶点处,当 ff 在附近达到最大值时, f′f' 为 0;并且当 ff 为负数时, f′f' 可以很大,如图 4.2 中的 x=−2x = -2 所示,其中 f(−2)=−2f(-2) = -2 但 f′(−2)=9。f'(-2) = 9\mathclose{\text{。}}在你绘制 f′f' 之前,请在每个点上问自己:“斜率多大?是上坡还是下坡?”而不是“高度多高?”。

符号

有几种导数的表示法,你将都会遇到。如果 y=f(x),y = f(x)\mathclose{\text{,}}这些都表示导数:

f′(x)=y′=dydx=dfdx=ddxf(x)=Df(x).f'(x) = y' = \frac{dy}{dx} = \frac{df}{dx} = \frac{d}{dx}f(x) = Df(x).
符号 读法
f′(x),f'(x)\mathclose{\text{,}} y′y' “x 的 f 的导数”,“y 的导数”
dydx\dfrac{dy}{dx} “y 对 x 的导数”
ddxf(x)\dfrac{d}{dx}f(x) “x 对 f 的导数”
Df(x)Df(x) “D 对 x 的 f”

先生符号简洁,表示函数。莱布尼茨的表示法 dydx\dfrac{dy}{dx} 显示了哪个变量在变化,并提示了它所代表的商 ΔyΔx\dfrac{\Delta y}{\Delta x} 的极限。符号 ddx\dfrac{d}{dx} 是一个指令,“对 xx 求导”: ddx(x2)=2x。\dfrac{d}{dx}\big(x^2\big) = 2x\mathclose{\text{。}}在某一点的值,写作 f′(a)f'(a) 或,在莱布尼茨的表示法中,

dydx∣x=a,\left.\frac{dy}{dx}\right|_{x=a},

读作 “dee y 由 dee x 在 x 等于 a 处”。对于下落的球,dsdt=9.8t\dfrac{ds}{dt} = 9.8t 和 dsdt∣t=2=19.6\left.\dfrac{ds}{dt}\right|_{t=2} = 19.6 m/s。物理学家也用点表示对时间的导数:s˙,\dot s\mathclose{\text{,}}读作 “s dot”,表示 dsdt。\dfrac{ds}{dt}\mathclose{\text{。}}

单位随符号一起给出:dsdt\dfrac{ds}{dt} 的单位是 ss 每 tt 的单位,此处为米每秒;温度(摄氏度)对时间(分钟)的导数单位是摄氏度每分钟。

注意

dydx\dfrac{dy}{dx} 不是分数:dydy 和 dxdx 这里不是数,也不能约去 dd 来得到 yx。\dfrac{y}{x}\mathclose{\text{。}} (对于 y=x2,y = x^2\mathclose{\text{,}}dydx=2x,\dfrac{dy}{dx} = 2x\mathclose{\text{,}}虽然 yx=x。)\dfrac{y}{x} = x\mathclose{\text{。)}} 模块 5 表明它通常表现得像分数,这也是它吸引人的地方。第二个错误:f′(3)f'(3) 表示“先求导,再代入 x=3”。x = 3\mathclose{\text{”。}}先代入 x=3x = 3 会得到一个数,而数不会变化,因此它的导数为 0:对于 f(x)=x2,f(x) = x^2\mathclose{\text{,}}f′(3)=2⋅3=6,f'(3) = 2 \cdot 3 = 6\mathclose{\text{,}}但 ddx(f(3))=ddx(9)=0。\dfrac{d}{dx}\big(f(3)\big) = \dfrac{d}{dx}(9) = 0\mathclose{\text{。}}

4

可导性

导数失效的情况

并非每个函数在每一点都有导数。图4.3展示了四个在0处均无导数的函数。其中,x1/3=x3x^{1/3} = \sqrt[3]{x}是实数立方根,对每个xx有定义(第1.4节),x2/3=(x3)2,x^{2/3} = \big(\sqrt[3]{x}\big)^2\mathclose{\text{,}}而HH是单位阶跃函数,H(x)=0H(x) = 0对应于x<0,x < 0\mathclose{\text{,}}H(x)=1H(x) = 1对应于x≥0。x \ge 0\mathclose{\text{。}}

在0点处不可导的四种情况:一个角点:abs{x}在左侧斜率为-1,在右侧斜率为1(虚线所示);一个尖点:x^{2/3}的斜率在左侧趋向于-infty,在右侧趋向于infty;一条垂直切线:x^{1/3}的图像在0点处变为垂直(虚线所示);一个跳跃:阶跃函数H在0点处不连续。
图 4.3

在0点处不可导的四种情况:一个角点:∣x∣\abs{x}在左侧斜率为−1,-1\mathclose{\text{,}}在右侧斜率为1(虚线所示);一个尖点:x2/3x^{2/3}的斜率在左侧趋向于−∞,-\infty\mathclose{\text{,}}在右侧趋向于∞;\infty\mathclose{\text{;}}一条垂直切线:x1/3x^{1/3}的图像在0点处变为垂直(虚线所示);一个跳跃:阶跃函数HH在0点处不连续。

由于前三个函数都是f(0)=0,f(0) = 0\mathclose{\text{,}}它们在0处的差商都是f(h)/h:f(h)/h\mathclose{\text{:}}

hh∣h∣h\dfrac{\abs{h}}{h}h2/3h\dfrac{h^{2/3}}{h}h1/3h\dfrac{h^{1/3}}{h}
0.10.1112.1542.1544.6424.642
0.0010.001111010100100
0.000010.000011146.4246.4221542154
−0.00001-0.00001−1-1−46.42-46.4221542154
−0.001-0.001−1-1−10-10100100
−0.1-0.1−1-1−2.154-2.1544.6424.642

三列在不同方式下表现。对于 ∣x∣,\abs{x}\mathclose{\text{,}}商在 0 的一侧为 1,另一侧为 −1;-1\mathclose{\text{;}}对于 x2/3,x^{2/3}\mathclose{\text{,}}它们在右侧趋向正无穷,在左侧趋向负无穷;对于 x1/3,x^{1/3}\mathclose{\text{,}}它们在两侧都趋向正无穷。如模块 2 所示,从一侧取极限可以精确描述每一列的行为。

定义 4.5单侧导数

函数 ff 在 aa 处的 右导数和左导数 为

f+′(a)=lim⁡h→0+f(a+h)−f(a)h,f−′(a)=lim⁡h→0−f(a+h)−f(a)h,\begin{aligned} f'_+(a) &= \lim_{h\to0^+}\frac{f(a + h) - f(a)}{h}, \\ f'_-(a) &= \lim_{h\to0^-}\frac{f(a + h) - f(a)}{h}, \end{aligned}

当这些极限存在(作为实数)时。函数在开区间上可微,如果它在区间的每一点都可微,并且函数在闭区间[a,b][a, b]上可微,如果它在(a,b)(a, b)上可微,且在aa处有右导数,在bb处有左导数。

读作 “a 的 f 的右导数” 和 “a 的 f 的左导数”。一个双边极限存在的条件是两个单边极限都存在并且相等(模块 2),因此 f′(a)f'(a) 存在当且仅当两个单边导数都存在并且相等,此时三个极限都是同一个数。现在依次分析这四个函数。

  • 尖角。对于 ∣x∣,\abs{x}\mathclose{\text{,}}当 h>0h > 0 时差商 ∣h∣/h\abs{h}/h 总为 1,当 h<0h < 0 时总为 −1。-1\mathclose{\text{。}}所以 f+′(0)=1f'_+(0) = 1 且 f−′(0)=−1。f'_-(0) = -1\mathclose{\text{。}}两个单侧导数都存在,但不相等,因此 f′(0)f'(0) 不存在。图像在这里有一个尖角,没有唯一切线。在 0 以外,∣x∣\abs{x} 可微:x<0x < 0 时导数为 −1,-1\mathclose{\text{,}}x>0x > 0 时为 1。神经网络的 ReLU max⁡(0,x)\max(0, x)(见第 1.3 节)在 0 处也有尖角,两个单侧导数分别为 0 和 1。训练软件仍要在此返回一个数值,通常取 0。
  • 尖点.对于 x2/3,x^{2/3}\mathclose{\text{,}}商是 h2/3/h=h−1/3=1/h3,h^{2/3}/h = h^{-1/3} = 1/\sqrt[3]{h}\mathclose{\text{,}}当 h→0+h \to 0^+ 时趋于 ∞,\infty\mathclose{\text{,}}当 h→0−h \to 0^- 时趋于 −∞。-\infty\mathclose{\text{。}}图像在原点处跌落并陡峭地离开:一个尖点,其中连续函数的商在一边趋于 ∞,\infty\mathclose{\text{,}}另一边趋于 −∞。-\infty\mathclose{\text{。}}
  • 垂直切线.对于 x1/3,x^{1/3}\mathclose{\text{,}}商是 h−2/3=1/(h3)2,h^{-2/3} = 1\big/\big(\sqrt[3]{h}\big)^2\mathclose{\text{,}}从两侧都趋于 ∞,\infty\mathclose{\text{,}}因此割线变得垂直。当 ff 在 aa 处连续且其差商从两侧趋于 ∞\infty(或从两侧趋于 −∞),-\infty\mathclose{\text{),}}图像在 aa 处有垂直切线,即直线 x=a。x = a\mathclose{\text{。}}放大后,图像看起来像这条直线,如图 4.1 所示;但垂直直线没有斜率,因此 f′(0)f'(0) 仍然不存在。
  • Jump. 对于 H,H\mathclose{\text{,}}当 H(0)=1H(0) = 1 时,商 h<0h < 0 的值为 H(h)−H(0)h=0−1h=−1h,\dfrac{H(h) - H(0)}{h} = \dfrac{0 - 1}{h} = -\dfrac1h\mathclose{\text{,}}它随着 h→0−h \to 0^- 而无界增长。下一个定理表明这并非偶然:一个函数在其不连续的点上永远不会可导。

可微函数连续

定理 4.1可导蕴含连续

若 ff 在 aa 可微,则 ff 在 aa 连续。

证明

对于 x≠ax \ne a 在 ff 定义的开区间内,写出

f(x)−f(a)=f(x)−f(a)x−a⋅(x−a).f(x) - f(a) = \frac{f(x) - f(a)}{x - a}\cdot(x - a).

如 x→a,x \to a\mathclose{\text{,}}根据定义的第二种形式,第一个因子趋于 f′(a),f'(a)\mathclose{\text{,}}第二个因子趋于 0。根据极限的乘积法则(模块 2),

lim⁡x→a(f(x)−f(a))=f′(a)⋅0=0,\lim_{x\to a}\big(f(x) - f(a)\big) = f'(a)\cdot0 = 0,

因此 lim⁡x→af(x)=f(a),\lim_{x\to a}f(x) = f(a)\mathclose{\text{,}}这正是 aa 处连续性的含义(模块 3)。

∎

假设在乘积法则中起作用,该法则需要两个因子的极限都是数。对于 x1/3x^{1/3} 在 0 处的情形,第一个因子趋于 ∞,\infty\mathclose{\text{,}}而该论证证明了什么都没有(尽管 x1/3x^{1/3} 恰好是连续的)。

两个结论值得分开。

  • 反言(Contrapositive): 如果 ff 在 aa 处不连续,则它在 aa 处不可导。这消除了图 4.3 中的跳跃间断点,以及其他所有间断点,立即成立。
  • 逆命题(Converse)是错误的: 一个连续函数不一定可导。 ∣x∣、\abs{x}\mathclose{\text{、}} x2/3x^{2/3} 和 x1/3x^{1/3} 在 0 处都是连续的(模块 3),且它们在该点均不可导。

因此,可导性是一个更强的性质。连续性在 aa 处表示图像在那里不会断裂;可导性则进一步要求:在 aa 处放大观察,图像看起来像一条非垂直的直线。这排除了尖点、拐点和垂直切线等情况,以及其他可能的失败情形:在 练习 4.11 中,一个连续函数在 0 附近振荡得如此之快,以至于从原点引出的割线从两侧都不会稳定在任何斜率上。

注意

ff在aa处连续,因此f′(a)f'(a)存在,这是定理4.1的逆命题,且为假:∣x∣\abs{x}在0处是标准反例。另一个相关错误是信任在推导f′f'的点之外使用的公式。∣x∣\abs{x}的导数是−1,-1\mathclose{\text{,}}对于x<0x < 0成立,对于x>0x > 0成立,某些程序将其写为sign⁡(x);\operatorname{sign}(x)\mathclose{\text{;}}但sign⁡(0)=0\operatorname{sign}(0) = 0并不使∣x∣\abs{x}在0处可导。第4.5节展示了SymPy正是这样做的。

深入一步可导意味着局部线性

图 4.1 表示了可导的几何意义:在 aa 附近,图像几乎是一条直线。以下是精确的陈述。对于斜率 m,m\mathclose{\text{,}}令

E(h)=f(a+h)−(f(a)+mh)E(h) = f(a + h) - \big(f(a) + mh\big)

为直线 y=f(a)+m(x−a)y = f(a) + m(x - a) 在 x=a+hx = a + h 处的误差。则 ff 在 aa 处可导,当且仅当 f′(a)=mf'(a) = m 恰好等于 E(h)/h→0E(h)/h \to 0 时 h→0。h \to 0\mathclose{\text{。}} 实际上,

E(h)h=f(a+h)−f(a)h−m,\frac{E(h)}{h} = \frac{f(a + h) - f(a)}{h} - m,

当差商趋于mm时,它恰好趋于0。对于任何其他斜率m1≠f′(a),m_1 \ne f'(a)\mathclose{\text{,}}相同的计算给出E1(h)/h→f′(a)−m1≠0。E_1(h)/h \to f'(a) - m_1 \ne 0\mathclose{\text{。}}因此,切线是通过(a,f(a))(a, f(a))的直线中,其误差比hh本身收缩得更快的那一条。对于f(x)=x3f(x) = x^3在a=1a = 1处,E(h)=(1+h)3−(1+3h)=3h2+h3,E(h) = (1 + h)^3 - (1 + 3h) = 3h^2 + h^3\mathclose{\text{,}}因此E(h)/h=3h+h2→0;E(h)/h = 3h + h^2 \to 0\mathclose{\text{;}}在图4.1的最后一个窗口中,其中∣h∣≤0.015,\abs{h} \le 0.015\mathclose{\text{,}}误差最多约为0.0007,小到看不见。模块7在此基础上构建线性近似,模块17使用相同的想法为多变量函数定义可微性。

5

第一条规则

每次从定义出发计算导数都很慢。少数几条规则,每条只需从定义证明一次,就能快速进行计算:使用本节的规则,你可以在一行内求导任何多项式。模块5添加了乘积法则、商法则和链式法则。

常数与幂

看一下目前定义所给出的内容:(x2)′=2x\big(x^2\big)' = 2x(例 4.5),例 4.6 中的计算显示 (x3)′=3x2。\big(x^3\big)' = 3x^2\mathclose{\text{。}}模式是:指数会降到前面,新的指数比原来小 1。例 4.6 也说明了这一点。

(x+h)3=x3+3x2h+3xh2+h3,(x + h)^3 = x^3 + 3x^2h + 3xh^2 + h^3,

x3x^3 与 −x3-x^3 抵消,除以 hh 后,项 3x2h3x^2h 变为 3x2,3x^2\mathclose{\text{,}}其余每一项都包含 h2,h^2\mathclose{\text{,}}因此在除后仍包含 h,h\mathclose{\text{,}}并在极限下消失。这就是证明的思路,下面的证明对每一项都进行这样的处理。

定理 4.2常数法则与幂法则

对于每一个常数 c,c\mathclose{\text{,}}每一个正整数 nn 和每一个实数 x,x\mathclose{\text{,}}

ddx(c)=0andddx(xn)=nxn−1.\frac{d}{dx}(c) = 0 \quad\text{and}\quad \frac{d}{dx}\big(x^n\big) = nx^{n-1}.

特别地,ddx(x)=1\dfrac{d}{dx}(x) = 1(此处 x0x^0 表示 1,也见于 x=0)。x = 0\mathclose{\text{)。}}

证明

常数。 若 f(x)=c,f(x) = c\mathclose{\text{,}}则每一个差商都是 c−ch=0,\dfrac{c - c}{h} = 0\mathclose{\text{,}}因此极限为 0。

幂。写出(x+h)n=(x+h)(x+h)⋯(x+h),(x + h)^n = (x + h)(x + h)\cdots(x + h)\mathclose{\text{,}}包含nn个因子。展开后,结果的每一项从nn个因子中各选xx或hh之一并将所选项相乘。每次选xx得到xn。x^n\mathclose{\text{。}}恰好从一个因子选hh而其余n−1n - 1个因子选xx得到xn−1h,x^{n-1}h\mathclose{\text{,}}且有nn种方式选择该因子,因此这些项之和为nxn−1h。nx^{n-1}h\mathclose{\text{。}}其余每项至少选hh两次,故含h2。h^2\mathclose{\text{。}}收集这些项,

(x+h)n=xn+nxn−1h+h2 Q(x,h),(x + h)^n = x^n + nx^{n-1}h + h^2\,Q(x, h),

其中 Q(x,h)Q(x, h) 是 xx 和 hh 的多项式(当 n=1n = 1 时还包括 Q=0)。Q = 0\mathclose{\text{)。}}因此,对于 h≠0,h \ne 0\mathclose{\text{,}}

(x+h)n−xnh=nxn−1+h Q(x,h).\frac{(x + h)^n - x^n}{h} = nx^{n-1} + h\,Q(x, h).

当 h→0,h \to 0\mathclose{\text{,}} Q(x,h)Q(x, h) 趋于 Q(x,0)Q(x, 0) 时,可以直接代入,因为它是 hh 的多项式;因此 h Q(x,h)h\,Q(x, h) 趋于 0⋅Q(x,0)=0,0 \cdot Q(x, 0) = 0\mathclose{\text{,}}商趋于 nxn−1。nx^{n-1}\mathclose{\text{。}}

∎
须知

准确数出选法,就得到二项式定理。从 nn 个因子中选出 kk 个贡献一个 h,h\mathclose{\text{,}}每种选法都产生一次 xn−khkx^{n-k}h^k 这一项,故

(x+h)n=xn+(n1)xn−1h+(n2)xn−2h2+⋯+hn,\begin{aligned} (x + h)^n &= x^n + \binom{n}{1}x^{n-1}h \\ &\quad + \binom{n}{2}x^{n-2}h^2 + \dots + h^n, \end{aligned}

其中 (nk)=n!k! (n−k)!\binom{n}{k} = \dfrac{n!}{k!\,(n - k)!} 读作「从 n 中选 k」,表示从 nn 个对象中选出 kk 个的选法数(其中 0!=1)。0! = 1\mathclose{\text{)。}}例如 (x+h)4=x4+4x3h+6x2h2+4xh3+h4。(x + h)^4 = x^4 + 4x^3h + 6x^2h^2 + 4xh^3 + h^4\mathclose{\text{。}}上面的证明只用到前两项。

公式 nxn−1nx^{n-1} 看起来不仅适用于正整数:例 4.4 求得 1/x=x−11/x = x^{-1} 在 2 处的斜率为 −14=(−1)⋅2−2,-\tfrac14 = (-1) \cdot 2^{-2}\mathclose{\text{,}}例 4.5 求得 (x)′=12x=12x−1/2。\big(\sqrt x\big)' = \dfrac{1}{2\sqrt x} = \tfrac12 x^{-1/2}\mathclose{\text{。}}定理 4.2 并未证明这些,因为其证明过程需要展开 nn 个因子。模块 5 证明了负整数的情况,模块 6 证明了所有实数指数的情况。

常数倍与和

定理 4.3常数倍法则与和法则

设 f、f\mathclose{\text{、}}gg 在 xx 处可微,cc 为常数。则 cf、cf\mathclose{\text{、}}f+gf + g 和 f−gf - g 在 xx 处可微,且

(cf)′(x)=c f′(x),(f+g)′(x)=f′(x)+g′(x),(f−g)′(x)=f′(x)−g′(x).\begin{aligned} (cf)'(x) &= c\,f'(x), \\ (f + g)'(x) &= f'(x) + g'(x), \\ (f - g)'(x) &= f'(x) - g'(x). \end{aligned}
证明

每个法则均可由模块 2 的极限法则推导得出。对于常数倍法则,函数 cfcf 的差商为

cf(x+h)−cf(x)h=c⋅f(x+h)−f(x)h,\begin{aligned} &\frac{cf(x + h) - cf(x)}{h} \\ &\quad= c\cdot\frac{f(x + h) - f(x)}{h}, \end{aligned}

哪个趋于 c f′(x)c\,f'(x) 依据常数倍法则。对于和,写 Δf=f(x+h)−f(x)\Delta f = f(x + h) - f(x) 和 Δg=g(x+h)−g(x)\Delta g = g(x + h) - g(x) 表示 ff 和 gg 的变化,依据模块 1 的 Δ。\Delta\mathclose{\text{。}}重新组合项后, f+gf + g 的变化为

(f(x+h)+g(x+h))−(f(x)+g(x))=Δf+Δg,\begin{aligned} &\big(f(x + h) + g(x + h)\big) \\ &\quad - \big(f(x) + g(x)\big) = \Delta f + \Delta g, \end{aligned}

因此, f+gf + g 的差商是 Δf+Δgh=Δfh+Δgh,\dfrac{\Delta f + \Delta g}{h} = \dfrac{\Delta f}{h} + \dfrac{\Delta g}{h}\mathclose{\text{,}}依据和法则趋于 f′(x)+g′(x)。f'(x) + g'(x)\mathclose{\text{。}}最后, f−g=f+(−1)g,f - g = f + (-1)g\mathclose{\text{,}}因此前两条规则给出 (f−g)′=f′+(−1)g′=f′−g′。(f - g)' = f' + (-1)g' = f' - g'\mathclose{\text{。}}

∎

假设很重要:公式需要 f′(x)f'(x) 和 g′(x)g'(x) 存在。没有它们,和可能可导也可能不可导: ∣x∣\abs{x} 和 −∣x∣-\abs{x} 在 0 处没有导数,但它们的和,即常数 0,有导数。

反复应用和法则,可以处理任意数量的项的和。换句话说:和的导数是导数的和,常数因子保持不变。这两条规则共同说明微分是 线性。

多项式

用这些规则,多项式逐项求导:

ddx(anxn+⋯+a1x+a0)=nanxn−1+⋯+2a2x+a1.\begin{aligned} &\frac{d}{dx}\big(a_nx^n + \dots + a_1x + a_0\big) \\ &\quad= na_nx^{n-1} + \dots + 2a_2x + a_1. \end{aligned}

常数项 a0a_0 消失。因此,每个多项式在 R\R 上均可导,其导数仍然是一个多项式,当次数至少为 1 时,次数减少 1。

例 4.7多项式的求导✓ 已检验

对 p(x)=4x5−3x3+7x−2p(x) = 4x^5 - 3x^3 + 7x - 2 求导,并求出在 x=1x = 1 处的切线方程。

根据和与差法则,逐项求导;根据常数倍法则,保持每个系数不变;然后使用幂法则和常数法则:

p′(x)=4ddx(x5)−3ddx(x3)+7ddx(x)−ddx(2)=4⋅5x4−3⋅3x2+7⋅1−0=20x4−9x2+7.\begin{aligned} p'(x) &= 4\frac{d}{dx}\big(x^5\big) - 3\frac{d}{dx}\big(x^3\big) \\ &\quad + 7\frac{d}{dx}(x) - \frac{d}{dx}(2) \\ &= 4 \cdot 5x^4 - 3 \cdot 3x^2 + 7 \cdot 1 - 0 \\ &= 20x^4 - 9x^2 + 7. \end{aligned}

在 x=1x = 1 处: p(1)=4−3+7−2=6p(1) = 4 - 3 + 7 - 2 = 6 和 p′(1)=20−9+7=18,p'(1) = 20 - 9 + 7 = 18\mathclose{\text{,}}因此切线方程为 y=6+18(x−1),y = 6 + 18(x - 1)\mathclose{\text{,}}即 y=18x−12。y = 18x - 12\mathclose{\text{。}}

例 4.8水平切线✓ 已检验

找出 g(x)=2x3−9x2+12x−4g(x) = 2x^3 - 9x^2 + 12x - 4 图像上具有水平切线的点。

水平切线的斜率为 0,因此解 g′(x)=0。g'(x) = 0\mathclose{\text{。}}根据法则,

g′(x)=6x2−18x+12=6(x2−3x+2)=6(x−1)(x−2),\begin{aligned} g'(x) &= 6x^2 - 18x + 12 \\ &= 6(x^2 - 3x + 2) \\ &= 6(x - 1)(x - 2), \end{aligned}

哪里恰好为 0 在 x=1x = 1 和 x=2。x = 2\mathclose{\text{。}}由于 g(1)=2−9+12−4=1g(1) = 2 - 9 + 12 - 4 = 1 和 g(2)=16−36+24−4=0,g(2) = 16 - 36 + 24 - 4 = 0\mathclose{\text{,}}图在 (1,1)(1, 1) 和 (2,0)(2, 0) 处有水平切线。对于 1<x<2,1 < x < 2\mathclose{\text{,}}一个因子为正,另一个为负,因此 g′(x)<0:g'(x) < 0\mathclose{\text{:}}那里的切线向下倾斜。模块 8 证明了图从 (1,1)(1, 1) 下降到 (2,0),(2, 0)\mathclose{\text{,}}并将这种推理转化为寻找极值的方法。

注意

三个诱人的错误规则。(1)乘积的导数不是导数的乘积:(x⋅x)′=(x2)′=2x,\big(x \cdot x\big)' = \big(x^2\big)' = 2x\mathclose{\text{,}}而非1⋅1=1。1 \cdot 1 = 1\mathclose{\text{。}}在模块5的乘积法则之前,先展开:ddx((x2+1)(x−3))=ddx(x3−3x2+x−3)=3x2−6x+1。\dfrac{d}{dx}\big((x^2 + 1)(x - 3)\big) = \dfrac{d}{dx}\big(x^3 - 3x^2 + x - 3\big) = 3x^2 - 6x + 1\mathclose{\text{。}}(2)常数的导数为0,无论其形式如何:ddx(π2)=0,\dfrac{d}{dx}\big(\pi^2\big) = 0\mathclose{\text{,}}而非2π,2\pi\mathclose{\text{,}}因为π2\pi^2是一个数。(3) 幂法则要求变量在底数且指数为常数:ddx(2x),\dfrac{d}{dx}\big(2^x\big)\mathclose{\text{,}}而非x⋅2x−1;x \cdot 2^{x-1}\mathclose{\text{;}}模块6中推导它。

动手计算使用 SymPy 计算导数

SymPy 使用 sp.diff 进行求导,它了解本节及更多规则。以下是例 4.7,即某点的导数,以及作为极限的定义本身:

Python
import sympy as sp
x, h = sp.symbols('x h')
p = 4*x**5 - 3*x**3 + 7*x - 2
dp = sp.diff(p, x)                 # the derivative p'(x)
print(dp)
print(dp.subs(x, 1))               # p'(1): differentiate first, then substitute
q = (p.subs(x, x + h) - p)/h       # the difference quotient
print(sp.limit(q, h, 0, '+-'))     # its two-sided limit: the definition
输出
20*x**4 - 9*x**2 + 7
18
20*x**4 - 9*x**2 + 7

sp.limit 的第四个参数 '+-' 要求双边极限;若不使用它,SymPy 仅从右侧趋近。答案可能与你的不同,因为 SymPy 可能因式分解或重新排列:

Python
print(sp.diff(p, x, 2))            # the second derivative (Section 4.6)
print(sp.diff(sp.sqrt(x), x))      # Example 4.5
输出
2*x*(40*x**2 - 9)
1/(2*sqrt(x))

实际上,80x3−18x80x^3 - 18x 是 2*x*(40*x**2 - 9) 的因式分解形式,是 20x4−9x2+720x^4 - 9x^2 + 7 的导数。现在注意第 4.4 节的警告。声明 xx 为实数(对于复数,SymPy 的答案更复杂):

Python
xr = sp.symbols('x', real=True)
d = sp.diff(sp.Abs(xr), xr)
print(d, d.subs(xr, 0))
print(sp.limit(sp.Abs(h)/h, h, 0, '+'), sp.limit(sp.Abs(h)/h, h, 0, '-'))
输出
sign(x) 0
1 -1

对于实数 x≠0,x \ne 0\mathclose{\text{,}}sign(x) 是正确的:对于 x<0x < 0 为 −1,-1\mathclose{\text{,}}对于 x>0x > 0 为 1。但代入 0 时得到 0,仿佛 ∣x∣\abs{x} 在那里导数为 0,而其差商的一边极限 1 和 −1-1 显示它不存在导数;使用 '+-' 时,SymPy 将拒绝双边极限,如模块 2 所示。一个关于 f′f' 的公式在 ff 不可导的点上告诉你什么也没有。

6

高阶导数和运动

导数 f′f' 是一个函数,因此也可以对其求导。

定义 4.6高阶导数

二阶导数是ff关于f′f'的导数:f′′=(f′)′。f'' = (f')'\mathclose{\text{。}}三阶导数是f′′′=(f′′)′,f''' = (f'')'\mathclose{\text{,}}一般地,nn阶导数f(n)f^{(n)}是f(n−1)f^{(n-1)}的导数,只要这些导数存在。在莱布尼茨记号中,对于y=f(x),y = f(x)\mathclose{\text{,}}

f′′(x)=d2ydx2=ddx(dydx),f(n)(x)=dnydxn.\begin{aligned} f''(x) &= \frac{d^2y}{dx^2} = \frac{d}{dx}\left(\frac{dy}{dx}\right), \\ f^{(n)}(x) &= \frac{d^ny}{dx^n}. \end{aligned}

读作: f′′(x)f''(x) 是 “f 双撇号在 x 处”, f′′′(x)f'''(x) 是 “f 三撇号在 x 处”, f(4)(x)f^{(4)}(x) 是 “f 在 x 处的四阶导数”, d2ydx2\dfrac{d^2y}{dx^2} 是 “二阶导数 dy/dx 平方”。这里的 2 表示求导次数,不是幂次。式子 f(4)f^{(4)} 中的括号将其与幂 f4f^4 区分开。

例 4.9多项式的全部导数✓ 已检验

求 p(x)=x4−2x3+5xp(x) = x^4 - 2x^3 + 5x 的所有导数。

不断应用这些规则:

p′(x)=4x3−6x2+5,p′′(x)=12x2−12x,p′′′(x)=24x−12,p(4)(x)=24,p(5)(x)=0,\begin{aligned} p'(x) &= 4x^3 - 6x^2 + 5, \\ p''(x) &= 12x^2 - 12x, \\ p'''(x) &= 24x - 12, \\ p^{(4)}(x) &= 24, \\ p^{(5)}(x) &= 0, \end{aligned}

和每一个后续导数也都为 0。每次求导都会使次数降低 1,因此一个次数为 nn 的多项式,其常数项的 nn 阶导数为非零,而所有高于 nn 阶的导数均为 0。对于 xnx^n 本身,其 nn 阶导数为 n(n−1)⋯2⋅1=n!;n(n - 1)\cdots2 \cdot 1 = n!\mathclose{\text{;}}这里为 p(4)=24=4!,p^{(4)} = 24 = 4!\mathclose{\text{,}}因为 pp 的主项系数为 1。

速度、加速度和加加速度

对于沿直线运动的物体,设在时间 tt 时的位置为 s(t),s(t)\mathclose{\text{,}}则前三个导数分别称为:

量 定义 单位
速度 v(t)=s′(t)=dsdtv(t) = s'(t) = \dfrac{ds}{dt} m/s
加速度 a(t)=v′(t)=s′′(t)=d2sdt2a(t) = v'(t) = s''(t) = \dfrac{d^2s}{dt^2} m/s²
加加速度 j(t)=a′(t)=s′′′(t)=d3sdt3j(t) = a'(t) = s'''(t) = \dfrac{d^3s}{dt^3} m/s³

单位是 ss 以米为单位,tt 以秒为单位。加速度是速度的变化率:下落的球具有 v(t)=9.8t,v(t) = 9.8t\mathclose{\text{,}}因此其加速度恒定,为 a(t)=9.8a(t) = 9.8 m/s²,即 模块 1 中的重力加速度。例 4.1 中的刹车汽车具有 v(t)=20−4tv(t) = 20 - 4t 和 a(t)=−4a(t) = -4 m/s²:为负值,因为其速度在减小。加加速度(jerk)是加速度的变化率,当你乘坐电梯或火车突然启动或停止时,你会感受到这种加加速度;电梯、火车和机械臂的设计旨在使其尽可能小。

aa 的符号表明 vv 是在增加还是减少(模块 8 证明了正导数意味着函数递增)。因此,当速度和加速度符号相同时,物体 加速;当它们符号不同时,物体 减速。

例 4.10一个来回运动的粒子✓ 已检验

假设一个粒子沿一条直线运动,其在 tt 秒后的位移为 s(t)=t3−6t2+9ts(t) = t^3 - 6t^2 + 9t 米,对于 t≥0;t \ge 0\mathclose{\text{;}}该运动由一些数值构成,便于计算。求其速度、加速度和冲击加速度。何时静止?何时向后运动?何时加速?

求三阶导数:

v(t)=3t2−12t+9=3(t−1)(t−3),a(t)=6t−12=6(t−2),j(t)=6.\begin{aligned} v(t) &= 3t^2 - 12t + 9 = 3(t - 1)(t - 3), \\ a(t) &= 6t - 12 = 6(t - 2), \\ j(t) &= 6. \end{aligned}

粒子静止时 v(t)=0:v(t) = 0\mathclose{\text{:}}在 t=1t = 1 时,在位置 s(1)=4s(1) = 4 米处,以及在 t=3t = 3 时回到 s(3)=0。s(3) = 0\mathclose{\text{。}}对于 1<t<3,1 < t < 3\mathclose{\text{,}}因数 t−1t - 1 和 t−3t - 3 符号相反,所以 v<0,v < 0\mathclose{\text{,}}粒子向后运动;在 t=1t = 1 之前和 t=3t = 3 之后, v>0,v > 0\mathclose{\text{,}}粒子向前运动。前 4 秒内,它从 0 米前进到 4 米,再回到 0 米,然后再次前进至 s(4)=4s(4) = 4 米:它总共移动了 4+4+4=124 + 4 + 4 = 12 米,尽管最终只偏离起点 4 米。

加速度在 t=2t = 2 处改变符号。比较 vv 和 aa 的符号:

区间 vv aa 粒子
0<t<10 < t < 1 ++ −- 向前运动,减速
1<t<21 < t < 2 −- −- 向后运动,加速
2<t<32 < t < 3 −- ++ 向后移动,速度减慢
t>3t > 3 ++ ++ 向前移动,速度加快

图4.4显示了三个图。其中ss处有水平切线,vv为0;其中vv处有水平切线,且在最低点t=2,t = 2\mathclose{\text{,}}aa为0:每个图都是其上方图的斜率图。

例4.10中的粒子。上图:其位置s(t),在t = 1和t = 3处有水平切线。中图:其速度v(t) = s'(t),在t = 1和t = 3为0,在中间为负值,此时粒子向后移动;其最低点在t = 2。下图:其加速度a(t) = v'(t), 在t = 2为0。
图 4.4

例4.10中的粒子。上图:其位置s(t),s(t)\mathclose{\text{,}}在t=1t = 1和t=3t = 3处有水平切线。中图:其速度v(t)=s′(t),v(t) = s'(t)\mathclose{\text{,}}在t=1t = 1和t=3t = 3为0,在中间为负值,此时粒子向后移动;其最低点在t=2。t = 2\mathclose{\text{。}}下图:其加速度a(t)=v′(t),a(t) = v'(t)\mathclose{\text{,}} 在t=2t = 2为0。

注意

速度不是速率,负加速度并不意味着减速。在例题4.10中,标记t=1t = 1和t=2t = 2之间的加速度是负的,但粒子却在加速:它以越来越快的速度向后运动,其速度从0变为−3-3 m/s,速率从0变为3 m/s。物体是否加速取决于标记vv和aa的符号是否相同,而不是仅取决于标记aa的符号。

7

数值微分

有时并没有可以求导的公式。一个函数可能仅以程序的形式已知,例如需要几分钟才能运行的模拟程序,或者仅通过测量得到,例如每秒记录一次的汽车位置。此时,导数是通过函数的几个值,利用差商和一个小的步长hh来估计的。两个选择决定了估计的精度:使用哪种商,以及使用哪种h。h\mathclose{\text{。}}

前向差分和中心差分

定义 4.7前向差分和中心差分

取步长 h>0,h > 0\mathclose{\text{,}}则 ff 在 aa 处的前向差分和中心差分分别为

forward:f(a+h)−f(a)h,central:f(a+h)−f(a−h)2h.\begin{aligned} &\text{forward:} && \frac{f(a + h) - f(a)}{h}, \\ &\text{central:} && \frac{f(a + h) - f(a - h)}{2h}. \end{aligned}

此类估计的误差为f′(a)f'(a)减去该估计值:即精确值减去近似值,正如本系列中每个近似值的情况。当估计值偏小时,误差为正;当估计值偏大时,误差为负。

前向差商本身就是差商,即从aa到a+ha + h的割线斜率。中心差商是从a−ha - h到a+ha + h的割线斜率,其区间以aa为中心。它是前向差商与后向差商 f(a)−f(a−h)h\dfrac{f(a) - f(a - h)}{h}的平均值,即用−h-h代替hh的商。若ff在aa处可微,则前向差商与后向差商在h→0h \to 0时均趋于f′(a),f'(a)\mathclose{\text{,}}它们的平均值亦然。

例 4.11x3x^3 的两种差分✓ 已检验

对于 f(x)=x3,f(x) = x^3\mathclose{\text{,}}求出 aa 处的前向差和中心差及其误差。

由例 4.6 的展开可得 (a+h)3=a3+3a2h+3ah2+h3。(a + h)^3 = a^3 + 3a^2h + 3ah^2 + h^3\mathclose{\text{。}}再用 −h-h 代替 h,h\mathclose{\text{,}}得 (a−h)3=a3−3a2h+3ah2−h3。(a - h)^3 = a^3 - 3a^2h + 3ah^2 - h^3\mathclose{\text{。}}所以

(a+h)3−a3h=3a2+3ah+h2,(a+h)3−(a−h)32h=6a2h+2h32h=3a2+h2.\begin{aligned} \frac{(a + h)^3 - a^3}{h} &= 3a^2 + 3ah + h^2, \\ \frac{(a + h)^3 - (a - h)^3}{2h} &= \frac{6a^2h + 2h^3}{2h} \\ &= 3a^2 + h^2. \end{aligned}

由于f′(a)=3a2,f'(a) = 3a^2\mathclose{\text{,}}误差,即f′(a)f'(a)减去估计值,恰好是−3ah−h2-3ah - h^2和−h2。-h^2\mathclose{\text{。}}在a=1a = 1处,当h=0.1h = 0.1时,前向差分为3.31,中心差分为3.01;当h=0.01h = 0.01时,它们分别为3.0301和3.0001。两个估计值都过大,因此两个误差均为负值。hh的十分之一削减使前向误差大约缩小十倍,而中心误差缩小百倍。在中心差分中,不随hh改变符号的项3ah23ah^2相互抵消:这就是中心化的优势所在。

这种模式适用于其他函数。表格显示了 x\sqrt x 在 a=4a = 4 处的两个误差,其中 f′(4)=14f'(4) = \tfrac14(例 4.4)精确计算:

hh14−forward\tfrac14 - \text{forward}14−central\tfrac14 - \text{central}
0.10.10.0015430.001543−1.954×10−5-1.954\times10^{-5}
0.010.010.00015610.0001561−1.953×10−7-1.953\times10^{-7}
0.0010.0011.562×10−51.562\times10^{-5}−1.953×10−9-1.953\times10^{-9}
0.00010.00011.562×10−61.562\times10^{-6}−1.953×10−11-1.953\times10^{-11}

每一行将 hh 除以 10;向前误差缩小为原来的 1/10,中心误差缩小为原来的 1/100。符号不同:此处向前差分太小,而中心差分太大。

中心差分也是在等时间间隔测量数据时的自然选择:每个内部时间点的估计值使用其两侧的测量值。并且 练习 1.11 显示,对于一个二次函数,例如下落球的 s(t)=4.9t2,s(t) = 4.9t^2\mathclose{\text{,}}中心差分在每个 hh 处都是精确的。

动手计算从测量中得到的速度

假设你只通过第 1.3 节中每隔 0.5 秒测量的位置表知道下落球。中心差分用于估计内部时间点的速度;NumPy 的 np.gradient 计算相同的中心差分,两端使用向前和向后差分:

Python
import numpy as np
dt = 0.5
t = np.arange(0, 3.01, dt)            # 0, 0.5, 1, ..., 3
s = 4.9*t**2                          # the measured positions
central = (s[2:] - s[:-2])/(2*dt)     # at t = 0.5, 1, ..., 2.5
print(central)
print(np.gradient(s, dt))
print(9.8*t)                          # the exact velocities
输出
[ 4.9  9.8 14.7 19.6 24.5]
[ 2.45  4.9   9.8  14.7  19.6  24.5  26.95]
[ 0.   4.9  9.8 14.7 19.6 24.5 29.4]

s[2:] - s[:-2] 从每个位置减去它前面两个位置的值。中心差分是精确的,正如练习 1.11 预测的那样。两端的估计值 2.45 和 26.95 m/s 各自偏离了 2.45 m/s。它们是模块 2 中的单边商 9.8a+4.9h,9.8a + 4.9h\mathclose{\text{,}}其中 h=0.5h = 0.5 在 t=0,t = 0\mathclose{\text{,}}而 h=−0.5h = -0.5 在 t=3,t = 3\mathclose{\text{,}}因此它们的误差是 9.8a−(9.8a+4.9h)=−4.9h:9.8a - (9.8a + 4.9h) = -4.9h\mathclose{\text{:}}起始端为 −2.45-2.45 m/s,末端为 2.452.45 m/s。

截断误差

当运算精确时剩余的误差来自于在步骤 h>0h > 0 停止而不是趋向于极限;这种误差称为 截断误差。为了比较此类误差,使用模块 3 中的大 O 记号,现在用 h→0h \to 0 表示,而不是用于大输入的情况。

定义 4.8Big-O 作为 h→0h \to 0

一个误差 E(h)E(h) 被称为 O(hp)O(h^p) 为 h→0,h \to 0\mathclose{\text{,}}读作“h 的 p 次方的大 O”,如果存在常数 CC 和 δ>0\delta > 0 使得 ∣E(h)∣≤C∣h∣p,\abs{E(h)} \le C\abs{h}^p\mathclose{\text{,}}当 0<∣h∣<δ0 < \abs{h} < \delta 时。

对于x3x^3在aa处,前向误差−3ah−h2-3ah - h^2为O(h),O(h)\mathclose{\text{,}}因为对于0<h<1,0 < h < 1\mathclose{\text{,}}h2≤hh^2 \le h以及如此∣3ah+h2∣≤(3∣a∣+1)h;\abs{3ah + h^2} \le (3\abs{a} + 1)h\mathclose{\text{;}}中心误差−h2-h^2为O(h2)。O(h^2)\mathclose{\text{。}}误差为O(hp)O(h^p)且无更优的方法具有阶p:p\mathclose{\text{:}}前向差分具有1阶,中心差分具有2阶。减半hh大致将1阶误差减半,将2阶误差减为四分之一。

这并不特指 x3:x^3\mathclose{\text{:}}

要点

如果 f′′f'' 在 aa 附近连续,则前向差分的误差约为 −h2f′′(a),-\tfrac{h}{2}f''(a)\mathclose{\text{,}}即 O(h)。O(h)\mathclose{\text{。}}如果 f′′′f''' 在 aa 附近连续,则中心差分的误差约为 −h26f′′′(a),-\tfrac{h^2}{6}f'''(a)\mathclose{\text{,}}即 O(h2)。O(h^2)\mathclose{\text{。}}模块 15 用泰勒定理证明了这两点。

对于 x3,x^3\mathclose{\text{,}}带入 f′′(a)=6af''(a) = 6a 和 f′′′(a)=6,f'''(a) = 6\mathclose{\text{,}}可得 −3ah-3ah 和 −h2,-h^2\mathclose{\text{,}}即例 4.11 中误差的主导部分。对于 x\sqrt x 在 4 处,其中 f′′(4)=−132f''(4) = -\tfrac{1}{32} 和 f′′′(4)=3256f'''(4) = \tfrac{3}{256}(根据分数指数幂的幂法则,模块 6 证明了这一点),它们预测 h64\tfrac{h}{64} 和 −h2512;-\tfrac{h^2}{512}\mathclose{\text{;}}对于 h=0.1,h = 0.1\mathclose{\text{,}}即 0.001560.00156 和 −0.0000195,-0.0000195\mathclose{\text{,}}接近上表中的第一行。

四舍五入误差与最佳步长

在纸上,越小的 hh 越好。但在计算机上则不然。浮点数(第 1.7 节 )大约携带 16 位有效数字:计算机能够存储的 1 与下一个更大的数之间的差距是 机器精度。

ε=2−52≈2.2×10−16,\varepsilon = 2^{-52} \approx 2.2 \times 10^{-16},

和一个计算值 ff 可能相差几个 ε∣f(a)∣\varepsilon\abs{f(a)} 单位。在前向差分中,当 hh 很小时,f(a+h)f(a + h) 和 f(a)f(a) 几乎相等,因此它们的差值只保留它们不同的几位数字:这种现象称为消去,如模块 2 所示。除以小的 hh 会放大舍入后剩余的部分。商的误差中由舍入引起的部分,其 舍入误差,可以是正负任意符号;其大小约为 ε∣f(a)∣/h,\varepsilon\abs{f(a)}/h\mathclose{\text{,}}并且随着 hh 变小而增大。

因此总误差有两部分,hh 减小时,这两部分的变化趋势相反。对于 x3x^3 在 1 处的前向差分,此时 ∣f(1)∣=1,\abs{f(1)} = 1\mathclose{\text{,}}总误差的绝对值大致不超过

3h+εh.3h + \frac{\varepsilon}{h}.

第一部分,截断误差的大小,当 hh 较大时较大;第二部分,舍入误差的大小,当 hh 较小时较大。

动手计算舍入误差实例

Python 的浮点数是上述描述的 16 位数字。机器 epsilon 及其含义:

Python
import sys
print(sys.float_info.epsilon)
print(1.0 + 1e-16 == 1.0, 1.0 + 1e-15 == 1.0)
输出
2.220446049250313e-16
True False

1 加上 10−1610^{-16} 后仍舍入为 1。来看看 f(x)=x3f(x) = x^3 在 a=1a = 1 处的两种差分,其中 f′(1)=3。f'(1) = 3\mathclose{\text{。}}当 hh 从 10−110^{-1} 缩小到 10−1510^{-15} 时,误差(精确值减估计值)如下:

Python
def f(x):
    return x**3

a, exact = 1.0, 3.0
print(f"{'h':>7}  {'forward error':>13}  {'central error':>13}")
for k in range(1, 16):
    h = 10.0**(-k)
    forward = (f(a + h) - f(a))/h
    central = (f(a + h) - f(a - h))/(2*h)
    print(f"{h:7.0e}  {exact - forward:13.2e}  {exact - central:13.2e}")
输出
      h  forward error  central error
  1e-01      -3.10e-01      -1.00e-02
  1e-02      -3.01e-02      -1.00e-04
  1e-03      -3.00e-03      -1.00e-06
  1e-04      -3.00e-04      -1.00e-08
  1e-05      -3.00e-05      -9.74e-11
  1e-06      -3.00e-06       8.03e-11
  1e-07      -3.02e-07      -8.63e-11
  1e-08      -3.97e-09       7.13e-09
  1e-09      -2.48e-07      -8.17e-08
  1e-10      -2.48e-07      -2.48e-07
  1e-11      -2.48e-07      -2.48e-07
  1e-12      -2.67e-04      -1.00e-04
  1e-13       2.40e-03       7.32e-04
  1e-14       2.40e-03       2.40e-03
  1e-15      -3.31e-01      -1.64e-01

读列。在前几行中,两个误差都是负数,接近例 4.11 中的截断误差 −3h−h2-3h - h^2 和 −h2:-h^2\mathclose{\text{:}}两个估计值都太大。前向误差的大小每行缩小十倍,正如 3h3h 所预测的,直到 h=10−7h = 10^{-7} 时约等于 −3×10−7。-3 \times 10^{-7}\mathclose{\text{。}}在 h=10−8h = 10^{-8} 处,它更小,约等于 −4×10−9,-4 \times 10^{-9}\mathclose{\text{,}}但这是偶然的:此时截断误差 −3h−h2≈−3.0×10−8-3h - h^2 \approx -3.0 \times 10^{-8} 和舍入误差,约等于 +2.6×10−8,+2.6 \times 10^{-8}\mathclose{\text{,}}几乎相互抵消。对于更小的 h,h\mathclose{\text{,}}舍入误差占主导地位,误差又开始增大,正负都有可能。中心误差每行缩小一百倍,直到 h=10−5h = 10^{-5} 时约等于 10−10,10^{-10}\mathclose{\text{,}}之后保持近似大小直到 h=10−7,h = 10^{-7}\mathclose{\text{,}}然后又开始增大。在 h=10−15h = 10^{-15} 处,两个估计值在小数点后第一位都出现了错误。

图4.5 绘制了在481个hh值下相同误差的大小。在对数坐标轴上,幂ChpCh^p表现为斜率为pp的直线,因为log⁡(Chp)=log⁡C+plog⁡h:\log\big(Ch^p\big) = \log C + p\log h\mathclose{\text{:}}截断误差的大小是斜率为1和2的直线,而舍入误差的大小则沿ε/h\varepsilon/h形成一条不规则的带,其斜率为−1。-1\mathclose{\text{。}}

在浮点运算中,对f(x) = x^3在a = 1处的向前(蓝色)和中心(橙色)差分,在10^{-16}与1之间执行481步h计算得到的误差大小,采用对数尺度。右侧截断误差占主导,沿虚线3h和h^2。左侧舍入误差占主导,呈锯齿状且接近varepsilon/h(灰色虚线)。点线标记最佳步长,向前差分约为10^{-8},中心差分约为5 times 10^{-6}。
图 4.5

在浮点运算中,对f(x)=x3f(x) = x^3在a=1a = 1处的向前(蓝色)和中心(橙色)差分,在10−1610^{-16}与1之间执行481步hh计算得到的误差大小,采用对数尺度。右侧截断误差占主导,沿虚线3h3h和h2。h^2\mathclose{\text{。}}左侧舍入误差占主导,呈锯齿状且接近ε/h\varepsilon/h(灰色虚线)。点线标记最佳步长,向前差分约为10−8,10^{-8}\mathclose{\text{,}}中心差分约为5×10−6。5 \times 10^{-6}\mathclose{\text{。}}

最佳步长出现在两类误差相互平衡之处。对于前向差分,当3h+ε/h3h + \varepsilon/h的两部分相等时其界最小(习题4.12证明了这一点),在h=ε/3≈9×10−9h = \sqrt{\varepsilon/3} \approx 9 \times 10^{-9}处,其值约为23ε≈5×10−8。2\sqrt{3\varepsilon} \approx 5 \times 10^{-8}\mathclose{\text{。}}对于中心差分,误差大小至多约为h2+ε/h,h^2 + \varepsilon/h\mathclose{\text{,}}在h=(ε/2)1/3≈5×10−6h = (\varepsilon/2)^{1/3} \approx 5 \times 10^{-6}处最小(模块8展示了如何找到此类极小值),其值约为7×10−11。7 \times 10^{-11}\mathclose{\text{。}}表格相符:其最小误差的大小位于那些步长附近。中心差分的结果,约为10−10,10^{-10}\mathclose{\text{,}}与估计值吻合;前向差分的结果,在h=10−8h = 10^{-8}处为−4×10−9,-4 \times 10^{-9}\mathclose{\text{,}}得益于幸运的抵消,其表现更优(习题4.12考察了最佳步长附近的行)。

要点

16位浮点数的一个经验法则:前向差分使用 h≈10−8h \approx 10^{-8} 时,大约能获得8位正确数字;中心差分使用 h≈10−5h \approx 10^{-5} 时,大约能获得10位正确数字。使 hh 更小,结果反而变差,而不是变好。当 aa 远离1时,应使用 h=10−5(1+∣a∣)h = 10^{-5}(1 + \abs{a}) 来缩放步长,如第4.2节中的小部件所用的那样,使用中心差分来计算你输入的函数。

注意

“误差越小 h,h\mathclose{\text{,}}导数越准确。” 精确算术中成立,浮点运算中不成立。对于 h=10−15,h = 10^{-15}\mathclose{\text{,}}在 1 处的前向差分 x3x^3 的误差约为 0.33,出现在第一位小数;对于 h=10−16,h = 10^{-16}\mathclose{\text{,}}1+h1 + h 舍入为 1,前向差分为 0。按经验法则选择 h,h\mathclose{\text{,}}或避免该问题:SymPy 可进行精确求导,自动微分(模块 5)可计算程序的导数,且无任何 h。h\mathclose{\text{。}}

8

你所学到的内容

  • 运动物体的速度和图象上切线的斜率都是差商的极限。这个极限称为导数,f′(a)=lim⁡h→0f(a+h)−f(a)h=lim⁡x→af(x)−f(a)x−a。f'(a) = \lim_{h\to0}\dfrac{f(a + h) - f(a)}{h} = \lim_{x\to a}\dfrac{f(x) - f(a)}{x - a}\mathclose{\text{。}}
  • 在 (a,f(a))(a, f(a)) 处的切线是 y=f(a)+f′(a)(x−a);y = f(a) + f'(a)(x - a)\mathclose{\text{;}}放大来看,可导函数的图象看起来就是这样。导数的单位是 ff 每 xx 单位。
  • 导数是一个函数 f′,f'\mathclose{\text{,}}在 xx 处的函数值是 ff 在 xx 处的斜率;它写作 f′(x)、f'(x)\mathclose{\text{、}}y′、y'\mathclose{\text{、}}dydx、\dfrac{dy}{dx}\mathclose{\text{、}}ddxf(x)\dfrac{d}{dx}f(x) 或 Df(x)。Df(x)\mathclose{\text{。}}
  • 一个函数在拐点、尖点、垂直切线或间断点处没有导数,也不在差商持续震荡的地方有导数。可导意味着连续;连续并不意味着可导(∣x∣\abs{x} 在 0 处)。
  • ddx(c)=0、\dfrac{d}{dx}(c) = 0\mathclose{\text{、}}ddx(xn)=nxn−1\dfrac{d}{dx}\big(x^n\big) = nx^{n-1} 对于正整数 n、n\mathclose{\text{、}}(cf)′=cf′(cf)' = cf' 和 (f±g)′=f′±g′:(f \pm g)' = f' \pm g'\mathclose{\text{:}}多项式逐项求导。
  • 高阶导数 f′′、f''\mathclose{\text{、}}f′′′、f'''\mathclose{\text{、}}f(n)。f^{(n)}\mathclose{\text{。}}沿直线运动时,速度 v=s′,v = s'\mathclose{\text{,}}加速度 a=s′′a = s'' 和急动度 j=s′′′;j = s'''\mathclose{\text{;}}当 vv 和 aa 符号相同时,物体加速。
  • 数值上,前向差分的截断误差为 O(h),O(h)\mathclose{\text{,}}中心差分的截断误差为 O(h2)。O(h^2)\mathclose{\text{。}}舍入误差随 ε/h\varepsilon/h 增长,因此在浮点运算中,最佳步长约为 10−810^{-8} 和 10−5,10^{-5}\mathclose{\text{,}}更小的步长会使情况恶化。
  • SymPy:sp.diff(f, x)、sp.diff(f, x, 2) 和 sp.limit(q, h, 0, '+-') 用于定义;一个关于 f′f' 的公式在 ff 不可导的点上说明不了什么。
9

练习

练习 4.1★从定义出发的导数
  • (a) 使用定义 f′(a)=lim⁡h→0f(a+h)−f(a)hf'(a) = \lim_{h\to0}\dfrac{f(a + h) - f(a)}{h} 来求 f′(−1)f'(-1) 在 f(x)=3x2−xf(x) = 3x^2 - x 处的值,以及在 x=−1x = -1 处的切线方程。
  • (b) 使用形式 lim⁡x→ag(x)−g(a)x−a\lim_{x\to a}\dfrac{g(x) - g(a)}{x - a} 来求 g′(3)g'(3) 在 g(x)=x2−4xg(x) = x^2 - 4x 处的值。
查看解答✓ 已检验

(a) 首先 f(−1)=3+1=4。f(-1) = 3 + 1 = 4\mathclose{\text{。}}将 −1+h-1 + h 代入,用括号括起来,并展开,用 (−1+h)2=1−2h+h2:(-1 + h)^2 = 1 - 2h + h^2\mathclose{\text{:}}

f(−1+h)=3(−1+h)2−(−1+h)=3(1−2h+h2)+1−h=3−6h+3h2+1−h=4−7h+3h2.\begin{aligned} &f(-1 + h) \\ &\quad= 3(-1 + h)^2 - (-1 + h) \\ &\quad= 3(1 - 2h + h^2) + 1 - h \\ &\quad= 3 - 6h + 3h^2 + 1 - h \\ &\quad= 4 - 7h + 3h^2. \end{aligned}

减去 f(−1)=4:f(-1) = 4\mathclose{\text{:}} f(−1+h)−f(−1)=−7h+3h2。f(-1 + h) - f(-1) = -7h + 3h^2\mathclose{\text{。}}因此

f′(−1)=lim⁡h→0−7h+3h2h=lim⁡h→0 (−7+3h)=−7.\begin{aligned} f'(-1) &= \lim_{h\to0}\frac{-7h + 3h^2}{h} \\ &= \lim_{h\to0}\,(-7 + 3h) = -7. \end{aligned}

切线方程为 y=4−7(x+1),y = 4 - 7(x + 1)\mathclose{\text{,}}即 y=−7x−3。y = -7x - 3\mathclose{\text{。}}当 x=−1x = -1 时,得到 7−3=4。7 - 3 = 4\mathclose{\text{。}}常见错误是漏掉 −x-x 中 −1+h-1 + h 外的括号,这会得到 −1+h,-1 + h\mathclose{\text{,}}而正确结果是 +1−h。+1 - h\mathclose{\text{。}}

(b) g(3)=9−12=−3,g(3) = 9 - 12 = -3\mathclose{\text{,}}因此 g(x)−g(3)=x2−4x+3=(x−1)(x−3)。g(x) - g(3) = x^2 - 4x + 3 = (x - 1)(x - 3)\mathclose{\text{。}}消去因子 x−3x - 3(允许这样做,因为 x≠3x \ne 3 在极限内):

g′(3)=lim⁡x→3(x−1)(x−3)x−3=lim⁡x→3 (x−1)=2.\begin{aligned} g'(3) &= \lim_{x\to3}\frac{(x - 1)(x - 3)}{x - 3} \\ &= \lim_{x\to3}\,(x - 1) = 2. \end{aligned}
练习 4.2★按规则对多项式求导

求导:

  • (a) f(x)=7x4−2x3+x−9f(x) = 7x^4 - 2x^3 + x - 9
  • (b) g(x)=(2x−1)(x2+3)g(x) = (2x - 1)(x^2 + 3)
  • (c) k(x)=x3−4xx,k(x) = \dfrac{x^3 - 4x}{x}\mathclose{\text{,}}用于 x≠0x \ne 0
  • (d) s(t)=πt2+π2s(t) = \pi t^2 + \pi^2
查看解答✓ 已检验

(a) 逐项进行: f′(x)=7⋅4x3−2⋅3x2+1−0=28x3−6x2+1。f'(x) = 7 \cdot 4x^3 - 2 \cdot 3x^2 + 1 - 0 = 28x^3 - 6x^2 + 1\mathclose{\text{。}}

(b) 先展开: g(x)=2x3+6x−x2−3=2x3−x2+6x−3,g(x) = 2x^3 + 6x - x^2 - 3 = 2x^3 - x^2 + 6x - 3\mathclose{\text{,}}因此 g′(x)=6x2−2x+6。g'(x) = 6x^2 - 2x + 6\mathclose{\text{。}}将因子的导数相乘 2⋅2x=4x2 \cdot 2x = 4x 是错误的:乘积的导数不是导数的乘积(模块 5 给出了正确的规则)。

(c) 对于 x≠0,x \ne 0\mathclose{\text{,}}将每一项除以 x:x\mathclose{\text{:}} k(x)=x2−4。k(x) = x^2 - 4\mathclose{\text{。}}因此 k′(x)=2x,k'(x) = 2x\mathclose{\text{,}}对于 x≠0:x \ne 0\mathclose{\text{:}} kk 在 0 处未定义,因此 k′k' 也未定义。

(d) π\pi 和 π2\pi^2 是常数: s′(t)=2πt,s'(t) = 2\pi t\mathclose{\text{,}}而常数项 π2\pi^2 贡献 0。

练习 4.3★一杯正在冷却的茶

假设一杯茶被倒入时温度为 t=0,t = 0\mathclose{\text{,}}经过 tt 分钟后的温度为 T(t)T(t) 摄氏度,其中 T(10)=62T(10) = 62 和 T′(10)=−1.5。T'(10) = -1.5\mathclose{\text{。}} (这些数字是虚构的。)

  • (a) T′(10)T'(10) 的单位是什么? T′(10)=−1.5T'(10) = -1.5 用文字怎么说?
  • (b) 使用 t=10t = 10 处的切线来估计 t=10.5t = 10.5 和 t=12t = 12 处的温度。
  • (c) dTdt∣t=10=−1.5\left.\dfrac{dT}{dt}\right|_{t=10} = -1.5 与 T′(10)=−1.5T'(10) = -1.5 是否相同?ddt(T(10))=−1.5\dfrac{d}{dt}\big(T(10)\big) = -1.5 是否相同?
查看解答✓ 已检验

(a) 摄氏度每分钟。倒入后十分钟,茶的冷却速率是每分钟 1.5 摄氏度:温度在下降,负号表示这一点。

(b) 切线是 T≈62−1.5(t−10)。T \approx 62 - 1.5(t - 10)\mathclose{\text{。}}在 t=10.5t = 10.5 时,它给出 62−0.75=61.2562 - 0.75 = 61.25 °C,在 t=12t = 12 时,它给出 62−3=5962 - 3 = 59 °C。第二个估计值不太可靠:切线只在 t=10t = 10 附近跟随曲线,茶在接近室温时冷却得更慢。

(c) 是的: dTdt∣t=10=−1.5\left.\dfrac{dT}{dt}\right|_{t=10} = -1.5 在莱布尼茨记号中是 T′(10)=−1.5。T'(10) = -1.5\mathclose{\text{。}}否: ddt(T(10))\dfrac{d}{dt}\big(T(10)\big) 是常数 T(10)=62T(10) = 62 的导数,因此是 0,而不是 −1.5。-1.5\mathclose{\text{。}}

练习 4.4★它在哪些点不可导?

对每个函数,找出它不可导的点,并说明每个点是拐点、尖点、垂直切线还是间断点。存在单侧导数时给出。

  • (a) f(x)=∣x−2∣f(x) = \abs{x - 2}
  • (b) g(x)=(x+1)2/3,g(x) = (x + 1)^{2/3}\mathclose{\text{,}}使用实数立方根
  • (c) k(x)=x2k(x) = x^2 对于 x<1,x < 1\mathclose{\text{,}}以及 k(x)=2xk(x) = 2x 对于 x≥1x \ge 1
查看解答✓ 已检验

(a) 在 2 以外任一点附近,ff 都等于 x−2x - 2 或 2−x,2 - x\mathclose{\text{,}}因此可微,导数为 1 或 −1。-1\mathclose{\text{。}}在 2 处,f(2)=0,f(2) = 0\mathclose{\text{,}}差商为 ∣h∣h。\dfrac{\abs{h}}{h}\mathclose{\text{。}}与 ∣x∣\abs{x} 在 0 处的情形一样,f+′(2)=1,f'_+(2) = 1\mathclose{\text{,}}而 f−′(2)=−1。f'_-(2) = -1\mathclose{\text{。}}于是图像在 x=2x = 2 处有尖角。

(b) 在−1-1处,g(−1)=0g(-1) = 0且商为(h2)1/3h=h−1/3,\dfrac{(h^2)^{1/3}}{h} = h^{-1/3}\mathclose{\text{,}}当h→0+h \to 0^+时它趋于∞,\infty\mathclose{\text{,}}当h→0−h \to 0^-时它趋于−∞。-\infty\mathclose{\text{。}}在x=−1x = -1处有一个尖点,x2/3x^{2/3}的尖点向左移动了1;此处不存在单侧导数。在其他地方gg是可微的:模块5的链式法则和模块6中分数指数的幂法则给出x≠−1x \ne -1的g′(x)=23(x+1)−1/3。g'(x) = \tfrac23(x + 1)^{-1/3}\mathclose{\text{。}}

(c) k(1)=2,k(1) = 2\mathclose{\text{,}}但当 x→1−x \to 1^- 时,k(x)=x2→1。k(x) = x^2 \to 1\mathclose{\text{。}}因此 kk 在 1 处不连续,由定理 4.1 它在该处也不可导。这里出现的是跳跃间断。取 k(1)=2,k(1) = 2\mathclose{\text{,}}h>0h > 0 与 h<0h < 0 的差商分别为

2(1+h)−2h=2,(1+h)2−2h=−1+2h+h2h.\begin{aligned} \frac{2(1 + h) - 2}{h} &= 2, \\ \frac{(1 + h)^2 - 2}{h} &= \frac{-1 + 2h + h^2}{h}. \end{aligned}

所以 k+′(1)=2,k'_+(1) = 2\mathclose{\text{,}}虽然左边的商随着 h→0−h \to 0^- 趋向于无穷大(其分子趋向于 −1),-1\mathclose{\text{),}}并且不存在左边导数。在远离 1 的地方,kk 在每个点附近都是多项式,因此可导。

练习 4.5★★切线与给定斜率

设 f(x)=x3−3x2。f(x) = x^3 - 3x^2\mathclose{\text{。}}

  • (a) 找出切线与直线 y=9x+1y = 9x + 1 平行的点,以及这些切线的方程。
  • (b) 是否存在一点,使得切线斜率为 −4?-4\mathclose{\text{?}}
查看解答✓ 已检验

(a) 平行线有相等的斜率,所以解 f′(x)=9.f'(x) = 9\mathclose{\text{.}} By the rules f′(x)=3x2−6x,f'(x) = 3x^2 - 6x\mathclose{\text{,}} and

3x2−6x=9  ⟺  x2−2x−3=0  ⟺  (x−3)(x+1)=0,\begin{aligned} &3x^2 - 6x = 9 \\ &\iff x^2 - 2x - 3 = 0 \\ &\iff (x - 3)(x + 1) = 0, \end{aligned}

所以 x=3x = 3 或 x=−1。x = -1\mathclose{\text{。}}由于 f(3)=27−27=0,f(3) = 27 - 27 = 0\mathclose{\text{,}}在 (3,0)(3, 0) 处的切线为 y=9(x−3),y = 9(x - 3)\mathclose{\text{,}}即 y=9x−27。y = 9x - 27\mathclose{\text{。}}由于 f(−1)=−1−3=−4,f(-1) = -1 - 3 = -4\mathclose{\text{,}}在 (−1,−4)(-1, -4) 处的切线为 y=−4+9(x+1),y = -4 + 9(x + 1)\mathclose{\text{,}}即 y=9x+5。y = 9x + 5\mathclose{\text{。}}

(b) 完成平方: f′(x)=3(x2−2x)=3(x−1)2−3≥−3f'(x) = 3(x^2 - 2x) = 3(x - 1)^2 - 3 \ge -3 对于每一个 x。x\mathclose{\text{。}} 每一条切线的斜率至少为 −3,-3\mathclose{\text{,}}因此没有一条切线的斜率为 −4。-4\mathclose{\text{。}} (方程 3x2−6x+4=03x^2 - 6x + 4 = 0 没有实数解:其判别式为 36−48<0。)36 - 48 < 0\mathclose{\text{。)}}

练习 4.6★★从定义出发的导数函数

设 f(x)=1x+1。f(x) = \dfrac{1}{x + 1}\mathclose{\text{。}}

  • (a) 使用定义来证明 f′(x)=−1(x+1)2f'(x) = -\dfrac{1}{(x + 1)^2} 对于 x≠−1。x \ne -1\mathclose{\text{。}}
  • (b) 求在 x=1x = 1 处的切线。
  • (c) 从公式解释为什么该图像的每一条切线都是向下倾斜的。
查看解答✓ 已检验

(a) 设 x≠−1。x \ne -1\mathclose{\text{。}}以 (x+h+1)(x+1)(x + h + 1)(x + 1) 为公分母,将分式通分:

f(x+h)−f(x)=1x+h+1−1x+1=(x+1)−(x+h+1)(x+h+1)(x+1)=−h(x+h+1)(x+1).\begin{aligned} &f(x + h) - f(x) \\ &\quad= \frac{1}{x + h + 1} - \frac{1}{x + 1} \\ &\quad= \frac{(x + 1) - (x + h + 1)}{(x + h + 1)(x + 1)} \\ &\quad= \frac{-h}{(x + h + 1)(x + 1)}. \end{aligned}

除以 h≠0h \ne 0 并令 h→0。h \to 0\mathclose{\text{。}}由于 x+1≠0,x + 1 \ne 0\mathclose{\text{,}}可以直接代入:

f′(x)=lim⁡h→0−1(x+h+1)(x+1)=−1(x+1)2.\begin{aligned} f'(x) &= \lim_{h\to0}\frac{-1}{(x + h + 1)(x + 1)} \\ &= -\frac{1}{(x + 1)^2}. \end{aligned}

在 x=−1x = -1 处,ff 无定义,故 f′f' 也无定义。

(b) f(1)=12f(1) = \tfrac12 和 f′(1)=−14,f'(1) = -\tfrac14\mathclose{\text{,}}因此切线是 y=12−14(x−1),y = \tfrac12 - \tfrac14(x - 1)\mathclose{\text{,}}即 y=34−x4。y = \tfrac34 - \tfrac{x}{4}\mathclose{\text{。}}

(c) 对于 x≠−1,x \ne -1\mathclose{\text{,}} (x+1)2>0,(x + 1)^2 > 0\mathclose{\text{,}}因此 f′(x)=−1(x+1)2<0:f'(x) = -\dfrac{1}{(x + 1)^2} < 0\mathclose{\text{:}}每条切线都有负斜率。

练习 4.7★★一个向上抛出的球

假设你从离地面 1.5 米高处以 14.7 m/s 的速度垂直向上抛出一个球。如果忽略空气阻力,它在 tt 秒后的高度是 y(t)=1.5+14.7t−4.9t2y(t) = 1.5 + 14.7t - 4.9t^2 米,直到落地。

  • (a) 找出它的速度和加速度,并说明它们的符号含义。
  • (b) 球何时达到最高点?此时高度是多少?
  • (c) 它何时落地?落地时的速度是多少?均保留两位小数。
查看解答✓ 已检验

(a) v(t)=y′(t)=14.7−9.8tv(t) = y'(t) = 14.7 - 9.8t m/s 和 a(t)=v′(t)=−9.8a(t) = v'(t) = -9.8 m/s²。高度向上测量,因此 v>0v > 0 表示上升, v<0v < 0 表示下降;恒定的负加速度是重力,向下拉。当球上升时, v>0v > 0 和 a<0a < 0 符号相反,因此速度减小;一旦下落,两者均为负,速度加快。

(b) 在顶部球停止上升且尚未开始下落: v(t)=0,v(t) = 0\mathclose{\text{,}}因此 t=14.7/9.8=1.5t = 14.7/9.8 = 1.5 s。然后 y(1.5)=1.5+22.05−11.025=12.525y(1.5) = 1.5 + 22.05 - 11.025 = 12.525 m。

(c) 球落地时 y(t)=0,y(t) = 0\mathclose{\text{,}}即 4.9t2−14.7t−1.5=0。4.9t^2 - 14.7t - 1.5 = 0\mathclose{\text{。}}根据求根公式,

t=14.7±14.72+4⋅4.9⋅1.52⋅4.9=14.7±245.499.8.\begin{aligned} t &= \frac{14.7 \pm \sqrt{14.7^2 + 4 \cdot 4.9 \cdot 1.5}}{2 \cdot 4.9} \\ &= \frac{14.7 \pm \sqrt{245.49}}{9.8}. \end{aligned}

负号给出负时间,即投掷前,因此 t=14.7+245.499.8≈3.10t = \dfrac{14.7 + \sqrt{245.49}}{9.8} \approx 3.10 s。然后 9.8t=14.7+245.49,9.8t = 14.7 + \sqrt{245.49}\mathclose{\text{,}}因此 v=14.7−9.8t=−245.49≈−15.67v = 14.7 - 9.8t = -\sqrt{245.49} \approx -15.67 m/s。球以约 15.67 m/s 落地,比投掷速度更快,因为它比手部释放点低 1.5 m:从顶部下落 12.525 m,比上升的 11.025 m 更远。

练习 4.8★★构造一个分段函数使其可导

求常数 bb 和 c,c\mathclose{\text{,}}使得

f(x)={x2if x≤1,bx+cif x>1f(x) = \begin{cases} x^2 & \text{if } x \le 1, \\ bx + c & \text{if } x > 1 \end{cases}

在 x=1x = 1 处可导。

查看解答✓ 已检验

需要两个条件。

连续性。 根据定理 4.1, ff 在 1 处必须连续。从左侧, f(x)=x2→1=f(1);f(x) = x^2 \to 1 = f(1)\mathclose{\text{;}}从右侧, f(x)=bx+c→b+c。f(x) = bx + c \to b + c\mathclose{\text{。}}因此 b+c=1。b + c = 1\mathclose{\text{。}}

单侧导数。 用 f(1)=1,f(1) = 1\mathclose{\text{,}}左导数商为 (1+h)2−1h=2+h,\dfrac{(1 + h)^2 - 1}{h} = 2 + h\mathclose{\text{,}}因此 f−′(1)=2。f'_-(1) = 2\mathclose{\text{。}}对于 h>0,h > 0\mathclose{\text{,}}右导数商为

b(1+h)+c−1h=(b+c−1)+bhh=b,\begin{aligned} &\frac{b(1 + h) + c - 1}{h} \\ &\quad= \frac{(b + c - 1) + bh}{h} = b, \end{aligned}

使用 b+c=1。b + c = 1\mathclose{\text{。}}因此 f+′(1)=b,f'_+(1) = b\mathclose{\text{,}}且当 b=2b = 2 时两者完全一致。然后 c=1−b=−1。c = 1 - b = -1\mathclose{\text{。}}

所以 b=2b = 2 和 c=−1。c = -1\mathclose{\text{。}}用这些值,1 处的两个单侧导数都是 2,因此 f′(1)=2。f'(1) = 2\mathclose{\text{。}}直线 y=2x−1y = 2x - 1 是 y=x2y = x^2 在 (1,1)(1, 1) 处的切线:图像沿其自身的切线离开抛物线。如果 b+c≠1,b + c \ne 1\mathclose{\text{,}}右导数商包含项 b+c−1h,\dfrac{b + c - 1}{h}\mathclose{\text{,}}该项随着 h→0+h \to 0^+ 趋于无穷大:不存在右导数,且 ff 在 1 处不可导,正如定理 4.1 预测的那样,对于在该点不连续的函数。

练习 4.9★★1/x 的前向差与中心差

设 f(x)=1xf(x) = \dfrac1x 和 a=1,a = 1\mathclose{\text{,}}使得 f′(1)=−1f'(1) = -1(例 4.4 的方法给出 f′(a)=−1/a2)。f'(a) = -1/a^2\mathclose{\text{)。}}

  • (a) 证明,对于 0<h<1,0 < h < 1\mathclose{\text{,}}前向差等于 −11+h,-\dfrac{1}{1 + h}\mathclose{\text{,}}中心差等于 −11−h2。-\dfrac{1}{1 - h^2}\mathclose{\text{。}}
  • (b) 计算两者及其误差,对于 h=0.1h = 0.1 和 h=0.01,h = 0.01\mathclose{\text{,}}保留六位小数。
  • (c) 在精确运算中,大致需要 hh 小到什么程度,才能使每个误差的大小小于 10−6?10^{-6}\mathclose{\text{?}}
查看解答✓ 已检验

(a) 前向差分:将两个项放在公共分母 1+h1 + h 上,

11+h−1=1−(1+h)1+h=−h1+h,\begin{aligned} \frac{1}{1 + h} - 1 &= \frac{1 - (1 + h)}{1 + h} \\ &= \frac{-h}{1 + h}, \end{aligned}

并除以 hh 得到 −11+h。-\dfrac{1}{1 + h}\mathclose{\text{。}} 中心差分:将两个项放在公共分母 (1+h)(1−h)=1−h2(1 + h)(1 - h) = 1 - h^2 上,

11+h−11−h=(1−h)−(1+h)1−h2=−2h1−h2,\begin{aligned} &\frac{1}{1 + h} - \frac{1}{1 - h} \\ &\quad= \frac{(1 - h) - (1 + h)}{1 - h^2} \\ &\quad= \frac{-2h}{1 - h^2}, \end{aligned}

并除以 2h2h 得到 −11−h2。-\dfrac{1}{1 - h^2}\mathclose{\text{。}}

(b) 误差为 f′(1)=−1f'(1) = -1 减去估计值:

−1+11+h=−h1+h,−1+11−h2=h21−h2.\begin{aligned} -1 + \frac{1}{1 + h} &= -\frac{h}{1 + h}, \\[6pt] -1 + \frac{1}{1 - h^2} &= \frac{h^2}{1 - h^2}. \end{aligned}

在两个步骤中:

  • h=0.1:h = 0.1\mathclose{\text{:}}前向差分 −0.909091,-0.909091\mathclose{\text{,}}误差 −0.090909;-0.090909\mathclose{\text{;}}中心差分 −1.010101,-1.010101\mathclose{\text{,}}误差 0.010101。0.010101\mathclose{\text{。}}
  • h=0.01:h = 0.01\mathclose{\text{:}}前向差分 −0.990099,-0.990099\mathclose{\text{,}}误差 −0.009901;-0.009901\mathclose{\text{;}}中心差分 −1.000100,-1.000100\mathclose{\text{,}}误差 0.000100。0.000100\mathclose{\text{。}}

前向差分太大,中心差分太小,因此它们的误差符号相反。

(c) 误差的大小为

h1+h<h,h21−h2>h2.\begin{aligned} \frac{h}{1 + h} &< h, \\[6pt] \frac{h^2}{1 - h^2} &> h^2. \end{aligned}

前向误差的大小略小于 h,h\mathclose{\text{,}}因此当 hh 接近 10−610^{-6} 时,其大小会低于 10−6;10^{-6}\mathclose{\text{;}}在 h=10−6h = 10^{-6} 处,它等于 10−6/(1+10−6)<10−6。10^{-6}/(1 + 10^{-6}) < 10^{-6}\mathclose{\text{。}}中心误差略大于 h2,h^2\mathclose{\text{,}}因此 hh 在约 10−310^{-3} 时就足够了: h=0.000999h = 0.000999 给出约 9.98×10−7。9.98 \times 10^{-7}\mathclose{\text{。}}中心差分达到相同精度时,步长可以大一千倍;在浮点运算中这一点很重要,因为较大的步长所受的舍入误差更少。

练习 4.10★★★幂法则的因式分解法
  • (a) 证明对于每一个正整数 n,n\mathclose{\text{,}}
    xn−an=(x−a)(xn−1+xn−2a+⋯+xan−2+an−1).\begin{aligned} &x^n - a^n \\ &\quad= (x - a)\big(x^{n-1} + x^{n-2}a \\ &\qquad + \dots + xa^{n-2} + a^{n-1}\big). \end{aligned}
  • (b) 利用 (a) 和定义的第二种形式 f′(a)=lim⁡x→af(x)−f(a)x−a,f'(a) = \lim_{x\to a}\dfrac{f(x) - f(a)}{x - a}\mathclose{\text{,}}给出幂法则的另一种证明。
查看解答✓ 已检验

(a) 展开右边。将长括号乘以 xx 得到

xn+xn−1a+xn−2a2+⋯+xan−1,\begin{aligned} &x^n + x^{n-1}a + x^{n-2}a^2 \\ &\quad + \dots + xa^{n-1}, \end{aligned}

并将其乘以 −a-a 得到

−xn−1a−xn−2a2−⋯−xan−1−an.\begin{aligned} &-x^{n-1}a - x^{n-2}a^2 \\ &\quad - \dots - xa^{n-1} - a^n. \end{aligned}

每一项的第1行除了 xnx^n 之外,都与第2行的一项相消,第2行除了 −an-a^n 之外的每一项都与第1行的一项相消。剩下的为 xn−an。x^n - a^n\mathclose{\text{。}}(对于 n=1,n = 1\mathclose{\text{,}}括号内是单项 1,恒等式为 x−a=x−a。)x - a = x - a\mathclose{\text{。)}}

(b) 对于 x≠a,x \ne a\mathclose{\text{,}}将 (a) 除以 x−a:x - a\mathclose{\text{:}}

xn−anx−a=xn−1+xn−2a+⋯+xan−2+an−1.\begin{aligned} &\frac{x^n - a^n}{x - a} \\ &\quad= x^{n-1} + x^{n-2}a \\ &\qquad + \dots + xa^{n-2} + a^{n-1}. \end{aligned}

右边是一个以 xx 为变量的多项式,共有 nn 项。当 x→ax \to a 时,直接代入将每一项变为 an−1,a^{n-1}\mathclose{\text{,}}因此极限为 nan−1。na^{n-1}\mathclose{\text{。}}因此 (xn)′=nxn−1\big(x^n\big)' = nx^{n-1} 在每一点 aa 处:再次应用幂法则,这次不需要二项式展开。

练习 4.11★★★起伏点在原点

设 f(x)=xsin⁡1xf(x) = x\sin\dfrac1x 和 g(x)=x2sin⁡1xg(x) = x^2\sin\dfrac1x 为 x≠0,x \ne 0\mathclose{\text{,}}且 f(0)=g(0)=0。f(0) = g(0) = 0\mathclose{\text{。}}

  • (a) 证明 ff 在 0 处连续但不可导。
  • (b) 证明 gg 在 0 处可导,导数为 g′(0)=0。g'(0) = 0\mathclose{\text{。}}

(使用模块2中的夹逼定理。)

查看解答✓ 已检验

(a) 对于 x≠0,x \ne 0\mathclose{\text{,}} ∣sin⁡(1/x)∣≤1,\abs{\sin(1/x)} \le 1\mathclose{\text{,}} 所以 −∣x∣≤xsin⁡1x≤∣x∣.-\abs{x} \le x\sin\dfrac1x \le \abs{x}\mathclose{\text{.}} 两个边界都趋于 0, 所以根据夹逼定理 lim⁡x→0f(x)=0=f(0):\lim_{x\to0}f(x) = 0 = f(0)\mathclose{\text{:}} ff 在 0 处连续. 其在 0 处的差商是

f(h)−f(0)h=hsin⁡(1/h)h=sin⁡1h,\begin{aligned} \frac{f(h) - f(0)}{h} &= \frac{h\sin(1/h)}{h} \\ &= \sin\frac1h, \end{aligned}

这在 h→0h \to 0 时没有极限. 在 h=1π/2+2kπh = \dfrac{1}{\pi/2 + 2k\pi} 时等于 1, 在 h=13π/2+2kπh = \dfrac{1}{3\pi/2 + 2k\pi} 时等于 −1,-1\mathclose{\text{,}} 对于每个正整数 k;k\mathclose{\text{;}} 两个序列 hh 都趋于 0. 如果极限 LL 要同时在 12\tfrac12 内接近 1 和 −1,-1\mathclose{\text{,}} 对于所有足够小的 hh 都不可能. 所以 f′(0)f'(0) 不存在: 从原点出发的割线斜率在 −1-1 和 1 之间无限摆动.

(b) gg 在 0 处的差商是

g(h)−g(0)h=h2sin⁡(1/h)h=hsin⁡1h,\begin{aligned} \frac{g(h) - g(0)}{h} &= \frac{h^2\sin(1/h)}{h} \\ &= h\sin\frac1h, \end{aligned}

与 −∣h∣≤hsin⁡1h≤∣h∣,-\abs{h} \le h\sin\dfrac1h \le \abs{h}\mathclose{\text{,}}因此根据夹逼定理趋于 0:g′(0)=0。g'(0) = 0\mathclose{\text{。}}函数 gg 在 0 附近无限震荡,但震荡被 y=x2y = x^2 和 y=−x2y = -x^2 所限制,两者在原点处都有水平切线 y=0,y = 0\mathclose{\text{,}}gg 也是如此。

练习 4.12★★★最佳步长

第4.7节 限定了 x3x^3 在 1 处的前向差分误差大小约为 3h+ε/h。3h + \varepsilon/h\mathclose{\text{。}}更一般地,设 E(h)=Ch+Kh,E(h) = Ch + \dfrac{K}{h}\mathclose{\text{,}}其中 CC 和 KK 是正数常数。

  • (a) 证明对每个 h>0h > 0 都有 E(h)≥2CK,E(h) \ge 2\sqrt{CK}\mathclose{\text{,}}等号恰在 h=K/Ch = \sqrt{K/C} 时成立。(展开 (Ch−K/h)2≥0。)\big(\sqrt{Ch} - \sqrt{K/h}\big)^2 \ge 0\mathclose{\text{。)}}
  • (b) 因此,最佳步长是 h∗=K/C,h^* = \sqrt{K/C}\mathclose{\text{,}}其中 EE 的两个部分相等。找出 h∗h^* 和 E(h∗)E(h^*) 对于 C=3C = 3 和 K=ε≈2.2×10−16K = \varepsilon \approx 2.2 \times 10^{-16} 的值,并与第4.7节的表格进行比较。
  • (c) 假设 ff 的值仅保留约8位有效数字,如同有噪声的测量值,因此 K=10−8。K = 10^{-8}\mathclose{\text{。}}此时的最佳步长和 EE 的最小值是多少?
查看解答✓ 已检验

(a) 当 h>0h > 0 时,两个平方根均有定义,且

(Ch−K/h)2=Ch−2Ch⋅K/h+Kh=Ch−2CK+Kh.\begin{aligned} &\Big(\sqrt{Ch} - \sqrt{K/h}\Big)^2 \\ &\quad= Ch - 2\sqrt{Ch \cdot K/h} + \frac{K}{h} \\ &\quad= Ch - 2\sqrt{CK} + \frac{K}{h}. \end{aligned}

平方永远不会为负,所以 Ch+Kh≥2CK。Ch + \dfrac{K}{h} \ge 2\sqrt{CK}\mathclose{\text{。}}等号成立当且仅当平方为 0,即当 Ch=K/h,\sqrt{Ch} = \sqrt{K/h}\mathclose{\text{,}}这意味着 Ch=K/h,Ch = K/h\mathclose{\text{,}}或 h2=K/C,h^2 = K/C\mathclose{\text{,}}或者(由于 h>0)h > 0\mathclose{\text{)}} h=K/C。h = \sqrt{K/C}\mathclose{\text{。}}在该点 h,h\mathclose{\text{,}}两部分 ChCh 和 K/hK/h 相等。

(b) h∗=ε/3≈8.6×10−9h^* = \sqrt{\varepsilon/3} \approx 8.6 \times 10^{-9} 和 E(h∗)=23ε≈5.2×10−8。E(h^*) = 2\sqrt{3\varepsilon} \approx 5.2 \times 10^{-8}\mathclose{\text{。}}第 4.7 节的表格在 h=10−8h = 10^{-8} 处,即最接近 h∗h^* 的步长,其前向误差最小,如预测。该处的误差,约 −4×10−9,-4 \times 10^{-9}\mathclose{\text{,}}其大小远小于模型的 5.2×10−8,5.2 \times 10^{-8}\mathclose{\text{,}}因为舍入误差恰好与截断误差符号相反,抵消了大部分。在相邻步长 10−710^{-7} 和 10−910^{-9} 处的误差,约 −3×10−7-3 \times 10^{-7} 和 −2.5×10−7,-2.5 \times 10^{-7}\mathclose{\text{,}}其大小与模型预测的(3.0×10−73.0 \times 10^{-7} 和 2.3×10−7)2.3 \times 10^{-7}\mathclose{\text{)}}一致。

(c) h∗=10−8/3≈5.8×10−5,h^* = \sqrt{10^{-8}/3} \approx 5.8 \times 10^{-5}\mathclose{\text{,}}和 E(h∗)=23×10−8≈3.5×10−4。E(h^*) = 2\sqrt{3 \times 10^{-8}} \approx 3.5 \times 10^{-4}\mathclose{\text{。}}对于 8 位有效数字的值,前向差分仅提供约 4 位正确数字,且需要更大的步长。噪声数据给出粗糙的导数。

10

自测

1
对于 f(x)=x2,f(x) = x^2\mathclose{\text{,}}哪个表达式是 f′(3)?f'(3)\mathclose{\text{?}}
2
若 f(2)=5f(2) = 5 和 f′(2)=−3f'(2) = -3 成立,则函数 ff 在点 x=2x = 2 处的图像的切线为
3
下列函数中,哪一个在 0 处连续但不可导?
4
ddx(5x4−2x+7)\dfrac{d}{dx}\big(5x^4 - 2x + 7\big) 是
5
若 y=x3,y = x^3\mathclose{\text{,}}则 dydx∣x=2\left.\dfrac{dy}{dx}\right|_{x=2} 等于
6
在 ff 的图像在某点有水平切线时, f′f' 的图像
7
一个粒子沿直线运动,经过 tt 秒后位置为 s(t)=t3−3ts(t) = t^3 - 3t 米。其在 t=2t = 2 处的加速度为
8
在浮点运算中,为什么 x3x^3 在 1 处的前向差分用 h=10−14h = 10^{-14} 比用 h=10−8h = 10^{-8} 更差?
学完这个模块了吗?