9. 数值微分

数值分析



周维祺

引入:导数的定义

差分的概念

  • 导数:f′(x)=lim⁡Δx→0f(x+Δx)−f(x)Δxf'(x)=\lim\limits_{\Delta x\to 0}\frac{f(x+\Delta x)-f(x)}{\Delta x}

  • 给定h>0h>0,差分:
    前向:D~f(x)=f(x+h)−f(x)h\tilde Df(x)=\frac{f(x+h)-f(x)}{h}\quad 后向:D~f(x)=f(x)−f(x−h)h\tilde Df(x)=\frac{f(x)-f(x-h)}{h}


    中心:D~f(x)=f(x+h)−f(x−h)2h\tilde Df(x)=\frac{f(x+h)-f(x-h)}{2h}

练习

验证若ff在xx处可导,则h→0h\to0时,上述三种差分均收敛于f′(x)f'(x)

差分法的收敛性

  • 前向:lim⁡h→0f(x+h)−f(x)h=f′(x)\lim\limits_{h\to0}\frac{f(x+h)-f(x)}{h}=f'(x)\quad (导数的定义)

  • 后向:lim⁡h→0f(x)−f(x−h)h=lim⁡−h→0f(x−h)−f(x)−h=f′(x)\lim\limits_{h\to0}\frac{f(x)-f(x-h)}{h}=\lim\limits_{-h\to0}\frac{f(x-h)-f(x)}{-h}=f'(x)\quad (同理)

  • 中心:(利用前、后向的收敛性)
    lim⁡h→0f(x+h)−f(x−h)2h=lim⁡h→0f(x+h)−f(x)2h+f(x)−f(x−h)2h=f′(x)\lim\limits_{h\to0}\frac{f(x+h)-f(x-h)}{2h}=\lim\limits_{h\to0}\frac{f(x+h)-f(x)}{2h}+\frac{f(x)-f(x-h)}{2h}=f'(x)

前向差分的误差

  • 设ff足够光滑,将ff泰勒展开:
    f(x+h)=f(x)+f′(x)h+f′′(ξ)2h2,ξ∈[x,x+h]f(x+h)=f(x)+f'(x)h+\frac{f''(\xi)}{2}h^2, \quad \xi\in[x,x+h]

  • ∣f(x+h)−f(x)h−f′(x)∣=∣f′′(ξ)2h∣∼O(h)|\frac{f(x+h)-f(x)}{h}-f'(x)|=|\frac{f''(\xi)}{2}h|\sim O(h)

  • 误差随步长线性减少

练习:推导后向差分的误差

中心差分的误差

  • f(x+h)=f(x)+f′(x)h+f′′(x)2h2+f′′′(ξ1)6h3f(x+h)=f(x)+f'(x)h+\frac{f''(x)}{2}h^2+\frac{f'''(\xi_1)}{6}h^3

  • f(x−h)=f(x)−f′(x)h+f′′(x)2h2−f′′′(ξ2)6h3f(x-h)=f(x)-f'(x)h+\frac{f''(x)}{2}h^2-\frac{f'''(\xi_2)}{6}h^3

  • ∣f(x+h)−f(x−h)2h−f′(x)∣=∣f′′′(ξ1)+f′′′(ξ2)12h2∣∼O(h2)|\frac{f(x+h)-f(x-h)}{2h}-f'(x)|=|\frac{f'''(\xi_1)+f'''(\xi_2)}{12}h^2|\sim O(h^2)

  • 误差随步长平方减少

二阶差分

  • f′′(x)≈f′(x+h2)−f′(x−h2)2⋅h2=f′(x+h2)−f′(x−h2)hf''(x)\approx \frac{f'(x+\frac{h}{2})-f'(x-\frac{h}{2})}{2\cdot\frac{h}{2}}=\frac{f'(x+\frac{h}{2})-f'(x-\frac{h}{2})}{h}\quad (中心差分)

  • f′(x+h2)≈f(x+h2+h2)−f(x+h2−h2)2⋅h2=f(x+h)−f(x)hf'(x+\frac{h}{2})\approx\frac{f(x+\frac{h}{2}+\frac{h}{2})-f(x+\frac{h}{2}-\frac{h}{2})}{2\cdot\frac{h}{2}}=\frac{f(x+h)-f(x)}{h}\quad (中心差分)

  • f′(x−h2)≈f(x−h2+h2)−f(x−h2−h2)2⋅h2=f(x)−f(x−h)hf'(x-\frac{h}{2})\approx\frac{f(x-\frac{h}{2}+\frac{h}{2})-f(x-\frac{h}{2}-\frac{h}{2})}{2\cdot\frac{h}{2}}=\frac{f(x)-f(x-h)}{h}\quad (中心差分)

  • f′′(x)≈f(x+h)−f(x)h−f(x)−f(x−h)hh=f(x+h)−2f(x)+f(x−h)h2f''(x)\approx\frac{\frac{f(x+h)-f(x)}{h}-\frac{f(x)-f(x-h)}{h}}{h}=\frac{f(x+h)-2f(x)+f(x-h)}{h^2}

练习

仿照一阶差分误差的推导方法,利用泰勒展开,推导二阶差分的误差

二阶差分的误差

  • f(x+h)=f(x)+f′(x)h+f′′(x)2h2+f(3)(x)6h3+f(4)(ξ1)24h4f(x+h)=f(x)+f'(x)h+\frac{f''(x)}{2}h^2+\frac{f^{(3)}(x)}{6}h^3+\frac{f^{(4)}(\xi_1)}{24}h^4

  • f(x−h)=f(x)−f′(x)h+f′′(x)2h2−f(3)(x)6h3+f(4)(ξ2)24h4f(x-h)=f(x)-f'(x)h+\frac{f''(x)}{2}h^2-\frac{f^{(3)}(x)}{6}h^3+\frac{f^{(4)}(\xi_2)}{24}h^4

  • ∣f(x+h)−2f(x)+f(x−h)h2−f′′(x)∣=∣f(4)(ξ1)+f(4)(ξ2)24h2∣∼O(h2)|\frac{f(x+h)-2f(x)+f(x-h)}{h^2}-f''(x)|=|\frac{f^{(4)}(\xi_1)+f^{(4)}(\xi_2)}{24}h^2|\sim O(h^2)

  • 误差随步长平方减少

拓展和思考

  • 拓展阅读:外插法

  • 数值微分的一般形式 D~f=∑kckf(xk)\tilde Df=\sum\limits_k c_kf(x_k)

  • 思考:先用插值法得p(x)p(x)作为f(x)f(x)的近似,再用p′(x)p'(x)作为f′(x)f'(x)的近似,是不是一个好方法?

拓展和思考

  • 积分是有界运算:
    ∣∫abf(x)−p(x)dx∣≤∥f−p∥(b−a)|\int_a^bf(x)-p(x)dx|\le\|f-p\|(b-a)

  • 若f(x)f(x)与p(x)p(x)的差异有界,则其积分的差异也有界

  • 微分是无界运算,即使f(x)f(x)与p(x)p(x)的差异有界,其微分的差异仍可以为无穷大。例:f(x)−g(x)=2xf(x)-g(x)=2\sqrt x,在(0,1)(0,1)上有界,但f′(x)−g′(x)=1/xf'(x)-g'(x)=1/\sqrt{x},在(0,1)(0,1)上无界

小结

  • 三种一阶差分法的公式

  • 二阶差分法的公式

  • 利用泰勒展开估计差分法的误差