Ch1 数学基础 | Mathematical Preliminaries
Jiepeng
Jiepeng
memset0
memset0

Copyright

数值分析课程的相关笔记在 Jiepeng 大佬的笔记 的基础之上修改而来,欢迎大家支持原作者。

1. §1.2 Roundoff Errors and Computer Arithmetic

1.1. 截断误差和舍入误差

  • 截断误差(truncation error): 使用截断的(或者说有限的)求和来近似无穷级数的和产生的误差。
    • 理论:e=n=01n!e=\sum\limits_{n=0}^{\infty} \frac{1}{n!}
    • 计算机: e=n=0N1n!e=\sum\limits_{n=0}^{N} \frac{1}{n!}
  • 舍入误差(roundoff error): 当计算机执行实数计算时产生的误差。这是因为计算机中的算术运算涉及到的数字只有有限位数。
    • 理论:0.33333330.3333333\cdots
    • 计算机: 0.3333330.333333

Discussion 1: 估计 01ex2dx\displaystyle{\int_{0}^{1} e^{-x^{2}} \text{d} x}

1.2. 截断法和舍入法

使用截断法或舍入法产生的误差都叫做 舍入误差(roundoff error)

  • 截断法(chopping):0.1119 -> 0.111
  • 舍入法(rounding):0.1119 -> 0.112

给定一个 实数的标准十进制浮点形式(normalized decimal floating-point form of a real number) y=0.d1d2d3dkdk+1×10ny = 0.d_1d_2d_3\ldots d_kd_{k+1}\ldots \times 10^n,则使用 chopping 或 rounding 的结果为:

fl(y)={0.d1d2d3dk×10n/* chopping */chop(y+5×10n(k+1))/* rounding */fl(y) = \begin{cases} 0.d_1d_2d_3\ldots d_k \times 10^n& \text{/* chopping */} \\ chop(y + 5 \times 10^{n-(k+1)}) & \text{/* rounding */} \end{cases}

1.3. 绝对误差与相对误差

pp^* 表示 pp近似值(approximation)

  • 绝对误差(absolute error)pp|p^* - p|
  • 相对误差(relative error)ppp\dfrac{|p^* - p|}{|p|}

有效位(significant digit / significant figure):对于 pp ,若近似值 pp^\ast 满足 ppp<5×10t\displaystyle{\dfrac{|p^* - p|}{|p|}<5 \times 10^{-t}} 则称 pp^{\ast}tt 有效位。

近似产生的误差

舍入误差如何影响我们的结果?

  • 相近数相减导致有效位数减少。
  • 除以小数或乘以大数导致误差放大。
  • 建议:先简化再输入到计算机。

误差产生

  • 两个近乎相等的数相减导致有效数字的相消,例如:a=0.123456789,b=0.123456788a=0.123456789, b=0.123456788,两者本来有 9 位有效数字,但是相减后只剩下 1 位有效数字。
  • 如果有限位的表示或计算产生了误差,则除以一个小数(或者乘以一个大数)会放大绝对误差。

Discussion 2: Evaluate f(x)=x36.1x2+3.2x+1.5f(x)=x^{3}-6.1x^{2}+3.2x+1.5 at x=4.71x=4.71 using 3-digit artihmetic

注意这里第二行第四列的 134.134.,它是从左边的 104.104. 乘以 4.714.71 得到,而不是从上面的 135.32301135.32301 截断得到。

1.4. 秦九韶算法 | Horner’s Method

乘法较多会导致式子的误差较大,秦九韶算法(Horner’s Method) 通过不断提取 xx 来减少乘法的次数,即把多项式 f(x)=anxn+an1xn1++a1x+a0f(x) = a_nx^n + a_{n-1}x^{n-1} + \ldots + a_1x + a_0 写成如下形式:

f(x)=(((anx+an1)x+an2)x+)x+a1)x+a0f(x) = ((\ldots(a_nx + a_{n-1})x + a_{n-2})x + \ldots)x + a_1)x + a_0

然后从最内层开始计算。

Discussion 2 (with Horner's Method)

  • Chopping:
    ((4.716.1)4.71+3.2)4.71+1.5=(1.394.71+3.2)4.71+1.5=(6.54+3.2)4.71+1.5=3.344.71+1.5=15.7+1.5=14.2\begin{aligned}&((4.71-6.1)4.71 + 3.2)4.71 + 1.5 \\=& (-1.39*4.71 + 3.2)4.71 + 1.5 \\=& (-6.54 + 3.2)4.71 + 1.5 \\=& -3.34*4.71 + 1.5 \\=& -15.7 + 1.5 \\=& -14.2\end{aligned}

    Relative error: 14.263899+14.214.2638990.44%\frac{|-14.263899 + 14.2|}{|-14.263899|} \approx 0.44\%

  • Rounding:
    ((4.716.1)4.71+3.2)4.71+1.5=(1.394.71+3.2)4.71+1.5=(6.55+3.2)4.71+1.5=3.354.71+1.5=15.8+1.5=14.3\begin{aligned}&((4.71-6.1)4.71 + 3.2)4.71 + 1.5 \\=& (-1.39*4.71 + 3.2)4.71 + 1.5 \\=& (-6.55 + 3.2)4.71 + 1.5 \\=& -3.35*4.71 + 1.5 \\=& -15.8 + 1.5 \\=& -14.3\end{aligned}

    Relative error: 14.263899+14.314.2638990.25%\frac{|-14.263899 + 14.3|}{|-14.263899|} \approx 0.25\%

2. §1.3 Algorithms and Convergence

2.1. 稳定性 | Stability

一个算法,如果初始数据的小变化会导致最终结果的小变化,则称为 稳定(stable);否则称为 不稳定(unstable)。如果只有在某些初始数据的选择下才稳定,则称为条件稳定(conditionally stable)

2.2. 误差增长

假设 E0>0E_0 > 0初始误差(initial error)EnE_n 是第 nn 步的误差。

  • 如果 EnCnE0E_n \approx CnE_0,则称为 线性增长(linear growth)

线性增长的误差通常是无法避免的,当 CCE0E_0 都很小的时候,结果通常是可以接受的。

  • 如果 EnCnE0E_n \approx C^nE_0,则称为 指数增长(exponential growth)

指数增长的误差应该避免,因为即使 E0E_0 很小,CnC^n 也会变得很大。这会导致不可接受的不准确性。

2.3. 收敛率 | Rate of Convergence

收敛率(rate of convergence):设 limh0F(h)=L\displaystyle{\lim_{h\to 0} F(h) = L}limh0G(h)=0\displaystyle{\lim_{h\to 0} G(h) = 0}。如果存在正常数 KK 使得 F(h)LKG(h)\displaystyle{|F(h)-L| \leq K|G(h)|} 对于足够小的 hh 成立,则记为 F(h)=L+O(G(h))F(h)=L+O(G(h))。我们通常取 G(h)=hp (p>0)G(h)=h^p\ (p>0),且一般只对最大的 pp 值感兴趣。

Homework 1.3.7: 求各函数的收敛速度

3. IEEE 754 Floating Representation

(1)sign(1+significand)2exponent-bias(-1)^\text{sign} \cdot (1+\text{significand}) \cdot 2^{\text{exponent-bias}}
  • 符号位 sign:一般来说正数就是 0 负数就是 1。
  • 尾数 significand / fraction:去除符号位后应被移到 1.xxxxx1.\text{xxxxx} 的形式,所以最高位的 1 可以被省略。
    • 对于一些不使用 hidden 1 策略的表示方式则移到 0.1xxxxx0.1\text{xxxxx} 的形式,注意不同的方式会影响阶码的值。
  • 指数 exponent:用移码表示,单精度浮点数的 偏移(bias)127127,双精度浮点数的偏移为 10231023(刚好是范围的一半)。

0.75-0.75 的单精度、双精度表示

  • 单精度浮点数
    • 最小值:指数 = 00000001,小数 = 000...000;x=±(1+0.0)×21127=±1.0×2126±1.2×1038x = \pm (1+0.0) \times 2^{1-127} = \pm 1.0 \times 2^{-126} \approx \pm 1.2 \times 10^{-38}
    • 最大值:指数 = 11111110,小数 = 111...111;x=±(1+0.111111)×2254127±2.0×2127±3.4×1038x = \pm (1+0.111\ldots 111) \times 2^{254-127} \approx \pm 2.0 \times 2^{127} \approx \pm 3.4 \times 10^{38}
    • 最小分度:2232^{-23}log102236.92\log_{10}{2^{-23}}\approx -6.92,故约为小数点后 6 位有效数字
  • 双精度浮点数:
    • 最小值:指数 = 00000000001,小数 = 000...000;x=±(1+0.0)×211023=±1.0×21022±2.2×10308x = \pm (1+0.0) \times 2^{1-1023} = \pm 1.0 \times 2^{-1022} \approx \pm 2.2 \times 10^{-308}
    • 最大值:指数 = 11111111110,小数 = 111...111;x=±(1+0.111111)×220461023±2.0×21023±1.8×10308x = \pm (1+0.111\ldots 111) \times 2^{2046-1023} \approx \pm 2.0 \times 2^{1023} \approx \pm 1.8 \times 10^{308}
    • 最小分度: 2522^{-52}log1025215.65\log_{10}{2^{-52}}\approx -15.65,故约为小数点后 15 位有效数字

4. 参考资料

评论

TABLE OF CONTENTS

1. §1.2 Roundoff Errors and Computer Arithmetic
1.1. 截断误差和舍入误差
1.2. 截断法和舍入法
1.3. 绝对误差与相对误差
1.4. 秦九韶算法 | Horner’s Method
2. §1.3 Algorithms and Convergence
2.1. 稳定性 | Stability
2.2. 误差增长
2.3. 收敛率 | Rate of Convergence
3. IEEE 754 Floating Representation
4. 参考资料

© 2018-2025 memset0.

All rights reserved.

Source Code

Built with Gatsby.js


Made with ❤️ in China