f = x² 在 x₀ = 1,h = 0.1 → 前向 2.1、后向 1.9、中心 2.0 在 1.1、1.0、0.9 处求 x² 得 1.21、1、0.81。前向 (1.21−1)/0.1 = 2.1;后向 (1−0.81)/0.1 = 1.9;中心 (1.21−0.81)/0.2 = 2.0——中心差分对二次函数精确。二阶导数也恰好等于 2。Finite-difference derivatives of f(x) = x^2 at x0 = 1 (h = 0.1)
Forward : (f(x0+h) - f(x0))/h = (1.210000 - 1.000000)/0.1 = 2.100000 |error| = 0.100000
Backward: (f(x0) - f(x0-h))/h = (1.000000 - 0.810000)/0.1 = 1.900000 |error| = 0.100000
Central : (f(x0+h) - f(x0-h))/(2h) = (1.210000 - 0.810000)/0.2 = 2.000000 |error| = 0.000000
Second derivative (central): (f(x0+h) - 2f(x0) + f(x0-h))/h^2 = 2.000000
f = sin(x) 在 x₀ = 0.5,h = 0.01 → 中心差分与 cos(0.5) 相差约 1.5×10⁻⁵ sin 在 0.5 处的精确导数为 cos(0.5) = 0.877583。单侧差分偏差约 4×10⁻³,而中心差分偏差仅约 1.5×10⁻⁵——一张表看清 O(h) 与 O(h²) 的差距。Finite-difference derivatives of f(x) = sin(x) at x0 = 0.5 (h = 0.01)
Forward : (f(x0+h) - f(x0))/h ≈ 0.875171 |error| ≈ 0.002412
Backward: (f(x0) - f(x0-h))/h ≈ 0.879965 |error| ≈ 0.002382
Central : (f(x0+h) - f(x0-h))/(2h) ≈ 0.877568 |error| ≈ 0.000015