18 / 90

第 18 天:有限差分、步长与浮点效应

通过定义、分步推导、检索练习与诚实的数值证据,让函数与变化变得可计算。

数学与微积分 480 分钟主动学习(8 小时专注学习)
01 120 分钟

有限差分是近似

Agent 辅助工程检查

前提条件

完成前一项活动;如遇困难,使用列出的恢复来源。

学习目标

由导数定义实现前向、后向和中心有限差分,保持 h 显式可见,并与解析答案比较,而不是把近似当作精确值。

操作说明

1. 代入数字之前,先用符号 h 写出三种格式:前向 [f(a+h) - f(a)]/h,后向 [f(a) - f(a-h)]/h,中心 [f(a+h) - f(a-h)]/(2h)。保持 h 的符号可见。
2. 利用 Day 17 的结论(x^2 在 3 处的前向差商恰为 6 + h),预测哪种格式最接近 f'(3) = 6。
3. 只计算一次 f(3.1)、f(3) 和 f(2.9),然后在三种格式中复用这三个值。
4. 列表写出每个估计值及其带符号的误差(估计值 - 6)。
5. 用泰勒展开解释规律:对 x^2,前向误差恰为 +h,后向误差恰为 -h,二者在中心格式中相互抵消;下一项含 f''',而二次函数的 f''' 为零。
6. 说明哪些量是精确的(f'(3)、函数值),哪些是近似(一般情况下格式的输出),并解释为什么这里中心差分精确只是特例,而不是规律。

时间安排(120 分钟):阅读 30 + 练习 55 + 检查 35。 阅读:OpenStax 第 3.1 节(作为差商极限的导数)和 SciPy derivative 页面概述。练习:三种格式、误差表和泰勒解释。检查:独立完成 x=2、h=.01 的掌握题。

练习与预测记录

对 x=3 处的 f(x)=x^2,取 h=.1,计算前向 [f(3+h)-f(3)]/h、后向 [f(3)-f(3-h)]/h、中心 [f(3+h)-f(3-h)]/(2h)。预测哪个最接近 f'(3)=6。

独立掌握标准

独立计算 f(x)=x^2 在 x=2、h=.01 处的三个估计值,与 4 比较,并说明哪些量是精确的、哪些是近似的。

权威来源资源与出处

linking CC BY-NC-SA 4.0 attribution noncommercial share-alike

OpenStax Calculus Volume 1

作者 / 机构: OpenStax, Rice University (Gilbert Strang, Edwin Herman, et al.) | 原始出处链接 ↗

对应章节 / 时间戳: Sections 2.1-2.3 (Functions, Limits, and the Derivative); Sections 3.1-3.2 (Derivative Rules)

验证版本与日期: 3rd edition, verified 2026-10-30

入选理由:

Open, systematic treatment of the limit definition and derivative rules with stable section locations.

来源前置条件:

Algebra, coordinate geometry, and function notation

安全回退方案(离线弹性):

The authored derivations, tables, and exercises in these three Study Days are complete offline recovery material; use the linked section only for optional comparison.

对比候选资源与选型分析 (3)
MIT OpenCourseWare 18.01SC Single Variable Calculus ↗ compared_selected_for_visual_practice [CC BY-NC-SA 4.0]

Strong exercises and transcripts, but the noncommercial share-alike terms and course navigation make OpenStax the primary stable text.

Paul's Online Math Notes: Calculus I ↗ compared_rejected_for_reuse [All Rights Reserved]

Useful reference, but rights and redistribution terms are less suitable for embedded recovery material.

SciPy Numerical Differentiation Documentation ↗ compared_selected_for_numerics [BSD-3-Clause]

A primary API reference for numerical derivative step-size behavior; it complements rather than replaces the hand derivation.

linking BSD-3-Clause

SciPy numerical derivative reference

作者 / 机构: SciPy Developers | 原始出处链接 ↗

对应章节 / 时间戳: derivative API: finite differences, step-size iteration, tolerances

验证版本与日期: SciPy documentation, verified 2026-10-30

入选理由:

Documents numerical differentiation as an approximation with finite step sizes and stopping criteria.

来源前置条件:

Python arithmetic and the definition of a derivative

安全回退方案(离线弹性):

The local Day 18 tables and pure-Python snippets reproduce the relevant finite-difference behavior without SciPy.

对比候选资源与选型分析 (2)
NumPy: numpy.gradient ↗ compared_alternative [BSD 3-Clause License]

Array-oriented gradient estimation on sampled grids; the SciPy derivative reference matches the pointwise finite-difference helper the exercises implement.

SymPy Calculus tutorial ↗ compared_alternative [BSD License]

Symbolic rather than numerical differentiation; useful for exact cross-checks but not the finite-difference practice target.

02 120 分钟

步长:截断误差与舍入误差

独立掌握检查(无 AI 辅助)

前提条件

完成前一项活动;如遇困难,使用列出的恢复来源。

学习目标

解释为什么最小的步长并不总是最好:截断误差通常随 h 减小而减小,而当邻近函数值变得无法区分时,浮点相消与舍入却会增大。

操作说明

1. 计算前先预测:中心差分的截断误差大约按 h^2 减小,舍入误差大约按 eps/h 增大(双精度下 eps ≈ 2.2e-16)。写下你预计二者交叉的位置。
2. 对 h = .1, 1e-3, 1e-5, 1e-8, 1e-12 计算中心估计 (sin(1+h) - sin(1-h))/(2h),至少显示 12 位有效数字。
3. 每个绝对误差都对照工作精度的 math.cos(1) 计算,而不是对照 10 位显示值 0.5403023059。
4. 标出误差不再减小、开始增大的那一行(转折点)。
5. 用两句话解释转折点:一句讲截断误差,一句讲相消与舍入。
6. 明确说明:这张表只展示了一个函数、一个点、一种精度,并不给出普遍适用的最佳 h。

时间安排(120 分钟):阅读 25 + 练习 60 + 检查 35。 阅读:SciPy derivative 页面(步长、容差)和活动 1 的笔记。练习:含误差和转折点的五行表。检查:独立复现三行并解释为什么 1e-12 比 1e-5 差的掌握题。

练习与预测记录

对 sin(1) 使用中心差分(其解析导数为 cos(1)≈0.5403023059(10 位十进制显示;误差应对照工作精度的 cos(1) 计算))。比较 h=.1, 1e-3, 1e-5, 1e-8 和 1e-12。解释最佳区间,而不是习惯性地选最小的 h。

独立掌握标准

无协助地用计算器或 Python 复现至少三行表值,计算相对 cos(1) 的绝对误差,并解释此处为什么 h=1e-12 比 h=1e-5 更差。

权威来源资源与出处

linking CC BY-NC-SA 4.0 attribution noncommercial share-alike

OpenStax Calculus Volume 1

作者 / 机构: OpenStax, Rice University (Gilbert Strang, Edwin Herman, et al.) | 原始出处链接 ↗

对应章节 / 时间戳: Sections 2.1-2.3 (Functions, Limits, and the Derivative); Sections 3.1-3.2 (Derivative Rules)

验证版本与日期: 3rd edition, verified 2026-10-30

入选理由:

Open, systematic treatment of the limit definition and derivative rules with stable section locations.

来源前置条件:

Algebra, coordinate geometry, and function notation

安全回退方案(离线弹性):

The authored derivations, tables, and exercises in these three Study Days are complete offline recovery material; use the linked section only for optional comparison.

对比候选资源与选型分析 (3)
MIT OpenCourseWare 18.01SC Single Variable Calculus ↗ compared_selected_for_visual_practice [CC BY-NC-SA 4.0]

Strong exercises and transcripts, but the noncommercial share-alike terms and course navigation make OpenStax the primary stable text.

Paul's Online Math Notes: Calculus I ↗ compared_rejected_for_reuse [All Rights Reserved]

Useful reference, but rights and redistribution terms are less suitable for embedded recovery material.

SciPy Numerical Differentiation Documentation ↗ compared_selected_for_numerics [BSD-3-Clause]

A primary API reference for numerical derivative step-size behavior; it complements rather than replaces the hand derivation.

linking BSD-3-Clause

SciPy numerical derivative reference

作者 / 机构: SciPy Developers | 原始出处链接 ↗

对应章节 / 时间戳: derivative API: finite differences, step-size iteration, tolerances

验证版本与日期: SciPy documentation, verified 2026-10-30

入选理由:

Documents numerical differentiation as an approximation with finite step sizes and stopping criteria.

来源前置条件:

Python arithmetic and the definition of a derivative

安全回退方案(离线弹性):

The local Day 18 tables and pure-Python snippets reproduce the relevant finite-difference behavior without SciPy.

对比候选资源与选型分析 (2)
NumPy: numpy.gradient ↗ compared_alternative [BSD 3-Clause License]

Array-oriented gradient estimation on sampled grids; the SciPy derivative reference matches the pointwise finite-difference helper the exercises implement.

SymPy Calculus tutorial ↗ compared_alternative [BSD License]

Symbolic rather than numerical differentiation; useful for exact cross-checks but not the finite-difference practice target.

03 120 分钟

数值实验与失败分析

Agent 辅助工程检查

前提条件

完成前一项活动;如遇困难,使用列出的恢复来源。

学习目标

运行一个可复现的纯 Python 有限差分实验,比较前向与中心误差,并在 h 变得极小时用 sqrt(1+h)-sqrt(1) 诊断相消。

操作说明

1. 脚本开头打印 sys.version,使运行可以复现。
2. 参照值单独保存:只计算一次 math.cos(1),绝不从有限差分推出它。
3. 遍历 h = .1, 1e-3, 1e-5, 1e-8, 1e-12,以科学计数法打印 sin(1) 的 h、前向误差和中心误差。
4. 加入相消的例子:h = 1e-8, 1e-12, 1e-16 时的前向估计 (sqrt(1+h) - sqrt(1))/h。运行前先预测在双精度下 1 + 1e-16 的结果,以及这对分子意味着什么。
5. 保留所有行,包括不稳定的行;隐藏坏行的实验不能作为证据。
6. 为每个区间写一行诊断:截断误差主导、相消/舍入主导,或有效数字完全丢失。

时间安排(120 分钟):阅读 20 + 练习 70 + 检查 30。 阅读:提示和活动 2 的表。练习:编写并运行脚本,记录完整输出。检查:将表和诊断与参考答案对照;若某行不一致,换一种格式重新运行。

练习与预测记录

写一个短脚本,打印 sin(1) 的 h、前向误差和中心误差。为平方根例子加入 h=1e-16,并预测分子在浮点中是否仍可区分。

独立掌握标准

独立作业必须包含可执行代码、至少四个 h 值的表格记录,以及区分截断误差与相消/舍入的书面诊断。

权威来源资源与出处

linking CC BY-NC-SA 4.0 attribution noncommercial share-alike

OpenStax Calculus Volume 1

作者 / 机构: OpenStax, Rice University (Gilbert Strang, Edwin Herman, et al.) | 原始出处链接 ↗

对应章节 / 时间戳: Sections 2.1-2.3 (Functions, Limits, and the Derivative); Sections 3.1-3.2 (Derivative Rules)

验证版本与日期: 3rd edition, verified 2026-10-30

入选理由:

Open, systematic treatment of the limit definition and derivative rules with stable section locations.

来源前置条件:

Algebra, coordinate geometry, and function notation

安全回退方案(离线弹性):

The authored derivations, tables, and exercises in these three Study Days are complete offline recovery material; use the linked section only for optional comparison.

对比候选资源与选型分析 (3)
MIT OpenCourseWare 18.01SC Single Variable Calculus ↗ compared_selected_for_visual_practice [CC BY-NC-SA 4.0]

Strong exercises and transcripts, but the noncommercial share-alike terms and course navigation make OpenStax the primary stable text.

Paul's Online Math Notes: Calculus I ↗ compared_rejected_for_reuse [All Rights Reserved]

Useful reference, but rights and redistribution terms are less suitable for embedded recovery material.

SciPy Numerical Differentiation Documentation ↗ compared_selected_for_numerics [BSD-3-Clause]

A primary API reference for numerical derivative step-size behavior; it complements rather than replaces the hand derivation.

linking BSD-3-Clause

SciPy numerical derivative reference

作者 / 机构: SciPy Developers | 原始出处链接 ↗

对应章节 / 时间戳: derivative API: finite differences, step-size iteration, tolerances

验证版本与日期: SciPy documentation, verified 2026-10-30

入选理由:

Documents numerical differentiation as an approximation with finite step sizes and stopping criteria.

来源前置条件:

Python arithmetic and the definition of a derivative

安全回退方案(离线弹性):

The local Day 18 tables and pure-Python snippets reproduce the relevant finite-difference behavior without SciPy.

对比候选资源与选型分析 (2)
NumPy: numpy.gradient ↗ compared_alternative [BSD 3-Clause License]

Array-oriented gradient estimation on sampled grids; the SciPy derivative reference matches the pointwise finite-difference helper the exercises implement.

SymPy Calculus tutorial ↗ compared_alternative [BSD License]

Symbolic rather than numerical differentiation; useful for exact cross-checks but not the finite-difference practice target.

04 120 分钟

检索、复习与独立掌握

独立掌握检查(无 AI 辅助)

前提条件

完成前一项活动;如遇困难,使用列出的恢复来源。

学习目标

把解析导数、不可导性、有限差分与数值误差整合成一套可辩护的验证流程,用于模型训练数学。

操作说明

1. 合上书和笔记。凭记忆依次回答题目的 (1)-(6)。
2. 在 (1) 和 (2) 中给出论证而不只是数值:写明 x^3 所用的法则,并写出 |x| 在 0 处的两个单侧斜率。
3. 在 (3) 中定义一套流程:一种格式、一组跨越几个数量级的 h 值,以及一条接受规则(例如在舍入误差主导之前估计值逐渐逼近的相对误差容差)。
4. 在 (4) 中列出要记录的证据字段:函数、点、dtype、h 值、估计值、参照值、误差和失败情况。
5. 在 (5) 中自己选定并写明函数、点和 h,把中心差分计算一直做到与解析导数比较的误差。
6. 在 (6) 中用自己的话写出局限性说明。
7. 对照参考答案批改。每个遗漏都回看 Day 16-18 中对应的活动,并独立重做一道等价题。

时间安排(120 分钟):阅读 15 + 练习 60 + 检查 45。 阅读:无(闭卷回忆)。练习:六部分作答和计算示例。检查:批改、回看,并独立重做每道遗漏的题。

练习与预测记录

闭卷:(1) 给出 x^3 在 2 处的导数;(2) 说明 |x| 在 0 处是否可导及原因;(3) 为检验黑箱光滑函数选择一种有限差分格式和 h 策略;(4) 列出你会记录的证据;(5) 附上由你自己选定并说明的函数、点和 h 的中心差分完整计算;(6) 明确说明有限差分检验是验证证据,而非可导性或精确性的证明。

独立掌握标准

独立掌握检查:提交四部分回答、一个完整的中心差分计算,并明确声明有限差分是验证证据,而非可导性或精确性的证明。

权威来源资源与出处

linking CC BY-NC-SA 4.0 attribution noncommercial share-alike

OpenStax Calculus Volume 1

作者 / 机构: OpenStax, Rice University (Gilbert Strang, Edwin Herman, et al.) | 原始出处链接 ↗

对应章节 / 时间戳: Sections 2.1-2.3 (Functions, Limits, and the Derivative); Sections 3.1-3.2 (Derivative Rules)

验证版本与日期: 3rd edition, verified 2026-10-30

入选理由:

Open, systematic treatment of the limit definition and derivative rules with stable section locations.

来源前置条件:

Algebra, coordinate geometry, and function notation

安全回退方案(离线弹性):

The authored derivations, tables, and exercises in these three Study Days are complete offline recovery material; use the linked section only for optional comparison.

对比候选资源与选型分析 (3)
MIT OpenCourseWare 18.01SC Single Variable Calculus ↗ compared_selected_for_visual_practice [CC BY-NC-SA 4.0]

Strong exercises and transcripts, but the noncommercial share-alike terms and course navigation make OpenStax the primary stable text.

Paul's Online Math Notes: Calculus I ↗ compared_rejected_for_reuse [All Rights Reserved]

Useful reference, but rights and redistribution terms are less suitable for embedded recovery material.

SciPy Numerical Differentiation Documentation ↗ compared_selected_for_numerics [BSD-3-Clause]

A primary API reference for numerical derivative step-size behavior; it complements rather than replaces the hand derivation.

linking BSD-3-Clause

SciPy numerical derivative reference

作者 / 机构: SciPy Developers | 原始出处链接 ↗

对应章节 / 时间戳: derivative API: finite differences, step-size iteration, tolerances

验证版本与日期: SciPy documentation, verified 2026-10-30

入选理由:

Documents numerical differentiation as an approximation with finite step sizes and stopping criteria.

来源前置条件:

Python arithmetic and the definition of a derivative

安全回退方案(离线弹性):

The local Day 18 tables and pure-Python snippets reproduce the relevant finite-difference behavior without SciPy.

对比候选资源与选型分析 (2)
NumPy: numpy.gradient ↗ compared_alternative [BSD 3-Clause License]

Array-oriented gradient estimation on sampled grids; the SciPy derivative reference matches the pointwise finite-difference helper the exercises implement.

SymPy Calculus tutorial ↗ compared_alternative [BSD License]

Symbolic rather than numerical differentiation; useful for exact cross-checks but not the finite-difference practice target.