YYnotesYYNotes

学习目标Learning Objectives - Note

#学习目标#关键概念#定义与公式#推导

第5周:数值微分Week 5 - Numerical Differentiation

第5周介绍如何由采样函数值近似导数。Bilingual notes on finite-difference derivative formulas.

第5周介绍如何由采样函数值近似导数。

Week 5 introduces derivative approximation from sampled function values.

学习目标

Learning Objectives

  • 使用前向、后向和中心差分近似一阶导数。

  • Use forward, backward, and central differences for first derivatives.

  • 由二次插值推导三点公式。

  • Derive the three-point formulas from quadratic interpolation.

  • 在非均匀与均匀网格上进行导数估计。

  • Handle both non-uniform and uniform grids in derivative estimation.

  • 利用差商(Divided Difference)结构计算二阶导数近似。

  • Compute second derivatives from divided-difference structure.

关键概念

Key Concepts

  • 差分法通过邻近函数值近似导数。

  • Finite differences approximate derivatives using nearby function values.

  • 网格记号:步长 hh,节点 xi=x0+ihx_i=x_0+ih(均匀网格)。

  • Grid notation: step size hh, nodes xi=x0+ihx_i=x_0+ih (uniform case).

  • 差商(Divided Difference)提供了从模型出发推导导数公式的路径。

  • Divided differences provide a model-based path to derivative formulas.

  • 在内点处,中心公式通常比单边公式更精确。

  • Central formulas are often more accurate than one-sided formulas at interior points.

定义与公式

Definitions and Formulas

前向差分:

Forward difference:

D+f(x)=f(x+h)f(x)hD^+f(x)=\dfrac{f(x+h)-f(x)}{h}.

后向差分:

Backward difference:

Df(x)=f(x)f(xh)hD^-f(x)=\dfrac{f(x)-f(x-h)}{h}.

三点中心一阶导(均匀网格):

Three-point central first derivative (uniform grid):

f(x)f(x+h)f(xh)2hf'(x)\approx \dfrac{f(x+h)-f(x-h)}{2h}.

三点二阶导:

Three-point second derivative:

f(x)f(x+h)2f(x)+f(xh)h2f''(x)\approx \dfrac{f(x+h)-2f(x)+f(x-h)}{h^2}.

非均匀三点模型:若节点为 p,q,rp,q,r,使用

Non-uniform three-point model: if nodes are p,q,rp,q,r, use

p2(x)=f[p]+f[p,q](xp)+f[p,q,r](xp)(xq)p_2(x)=f[p]+f[p,q](x-p)+f[p,q,r](x-p)(x-q),再计算 p2(p),p2(q),p2(r)p_2'(p),p_2'(q),p_2'(r)

p2(x)=f[p]+f[p,q](xp)+f[p,q,r](xp)(xq)p_2(x)=f[p]+f[p,q](x-p)+f[p,q,r](x-p)(x-q) and evaluate p2(p),p2(q),p2(r)p_2'(p),p_2'(q),p_2'(r).

推导

Derivations

中心差分是前向与后向的平均

Central Difference as Average of Forward and Backward

D+f(x)+Df(x)2=f(x+h)f(xh)2h\dfrac{D^+f(x)+D^-f(x)}{2}=\dfrac{f(x+h)-f(x-h)}{2h}.

该表达在泰勒展开中会抵消一阶偏差项。

This cancels first-order bias terms in Taylor expansion.

由牛顿二次插值推导三点公式

Three-Point Formula from Newton Quadratic

Fit p2(x)p_2(x) through (p,P),(q,Q),(r,R)(p,P),(q,Q),(r,R).

通过 (p,P),(q,Q),(r,R)(p,P),(q,Q),(r,R) 拟合 p2(x)p_2(x)

p2p_2 求导并在各节点取值以近似导数。

Differentiate p2p_2 and evaluate at each node to approximate derivatives.

当间距均匀且 p=xh,q=x,r=x+hp=x-h,q=x,r=x+h 时,公式化简为中心差分形式。

For uniform spacing p=xh,q=x,r=x+hp=x-h,q=x,r=x+h, formulas simplify to central differences.

例题精讲

Worked Examples

例题模块1:f(x)=x2f(x)=x^2x=1,h=0.1x=1,h=0.1 的估计

Example Block 1: f(x)=x2f(x)=x^2 at x=1x=1, h=0.1h=0.1

前向差分:1.2110.1=2.1\dfrac{1.21-1}{0.1}=2.1

Forward difference: 1.2110.1=2.1\dfrac{1.21-1}{0.1}=2.1.

后向差分:10.810.1=1.9\dfrac{1-0.81}{0.1}=1.9

Backward difference: 10.810.1=1.9\dfrac{1-0.81}{0.1}=1.9.

中心差分:1.210.810.2=2.0\dfrac{1.21-0.81}{0.2}=2.0(本例恰为精确值)。

Central difference: 1.210.810.2=2.0\dfrac{1.21-0.81}{0.2}=2.0 (exact here).

例题模块2:0.1,0,0.1-0.1,0,0.1 的指数函数样本

Example Block 2: Exponential Samples at 0.1,0,0.1-0.1,0,0.1

使用三点框架估计 f(0.1),f(0),f(0.1)f'(-0.1),f'(0),f'(0.1)

Use non-uniform/three-point framework to estimate f(0.1),f(0),f(0.1)f'(-0.1),f'(0),f'(0.1).

与单边差分相比,中心估计在内点更接近真值 exe^x

Compared with one-sided differences, central estimates better match true value exe^x at interior point.

例题模块3:在 0.9,1.0,1.10.9,1.0,1.1 的三点多项式恢复

Example Block 3: Three-Point Polynomial Recovery at 0.9,1.0,1.10.9,1.0,1.1

f(x)=x2f(x)=x^2,重构二次模型可得精确导数 f(0.9)=1.8f'(0.9)=1.8f(1)=2f'(1)=2f(1.1)=2.2f'(1.1)=2.2

For f(x)=x2f(x)=x^2, reconstructed quadratic gives exact derivatives f(0.9)=1.8f'(0.9)=1.8, f(1)=2f'(1)=2, f(1.1)=2.2f'(1.1)=2.2.

误差(Error)分析

Error Analysis

  • 前向/后向差分是一阶精度:误差(Error) O(h)O(h)

  • Forward/backward differences are first-order accurate: error O(h)O(h).

  • 中心一阶导公式是二阶精度:误差(Error) O(h2)O(h^2)

  • Central first-derivative formula is second-order accurate: error O(h2)O(h^2).

  • 在均匀网格上,三点二阶导公式同样是二阶精度。

  • Three-point second-derivative formula is also second-order accurate on uniform grids.

  • 即使截断误差(Error)hh 减小,过小 hh 也会放大舍入误差(Error)

  • Too small hh can increase round-off error even if truncation error decreases.

常见错误

Common Mistakes

警示模块

Warning Block

  • 在中心差分分母中误写 2h2h

  • Using 2h2h incorrectly in central denominator.

  • 在非均匀节点上误用均匀网格公式。

  • Applying uniform-grid formulas on non-uniform nodes.

  • 差商(Divided Difference)中混淆索引顺序。

  • Mixing index order in divided differences.

  • 解释导数量级时忽略 hh 的单位与尺度。

  • Ignoring unit/scale of hh when interpreting derivative magnitude.

总结

Summary

总结模块

Summary Block

  • 第5周建立了由离散数据进行导数估计的实用方法。

  • Week 5 established practical derivative estimation from tabulated data.

  • 三点框架统一了非均匀与均匀情形。

  • The three-point framework unifies non-uniform and uniform formulas.

  • 中心差分是相对于单边差分的重要精度提升。

  • Central differences are a key accuracy upgrade over one-sided approximations.

练习题

Practice Questions

  • f(x)=lnxf(x)=\ln x,取 h=0.1h=0.1,分别用前向、后向、中心差分估计 f(2)f'(2)

  • Estimate f(2)f'(2) for f(x)=lnxf(x)=\ln x using forward, backward, and central differences with h=0.1h=0.1.

  • 给定节点 p=1,q=1.4,r=2p=1,q=1.4,r=2,用差商(Divided Difference)形式推导 p2(q)p_2'(q)

  • Using nodes p=1p=1, q=1.4q=1.4, r=2r=2, derive p2(q)p_2'(q) in divided-difference form.

  • x=0x=0 处比较 f(x)=exf(x)=e^x 的数值二阶导与精确值,并测试多个 hh

  • Compare numerical and exact second derivatives for f(x)=exf(x)=e^x at x=0x=0 for several hh values.