要避免除数绝对值远远小于被除数绝对值的除法
用绝对值小的数作除数,舍人误差会增大,如计算 x y \frac xy yx,若 0 < ∣ y ∣ < ∣ x ∣ 0<|y|<|x| 0<∣y∣<∣x∣,则可能对计算结果带来严重影响,应尽量避免。
例
线性方程组 { 0.000001 x 1 + x 2 = 1 2 x 1 + x 2 = 2 \begin{cases}0.000001x_1+x_2=1\\2x_1+x_2=2\end{cases} {0.000001x1+x2=12x1+x2=2的准确解为
x 1 = 200000 399999 = 0.50000125 x_1=\frac{200000}{399999}=0.50000125 x1=399999200000=0.50000125
x 2 = 199 998 199 999 = 0.999995 x_2= \frac {199\:998}{199\:999}= 0. 999 995 x2=199999199998=0.999995
模仿计算机实际计算过程,在四位浮点十进制数下用消去法求解,上述方程组写成
{ 1 0 − 4 × 0.1000 x 1 + 1 0 1 × 0.1000 x 2 = 1 0 1 × 0.1000 1 0 1 × 0.2000 x 1 + 1 0 1 × 0.1000 x 2 = 1 0 1 × 0.2000 \begin{cases}10^{-4}\times0.1000x_1+10^1\times0.1000x_2=10^1\times0.1000\\10^1\times0.2000x_1+10^1\times0.1000x_2=10^1\times0.2000\end{cases} {10−4×0.1000x1+101×0.1000x2=101×0.1000101×0.2000x1+101×0.1000x2=101×0.2000
若用 ( 1 0 − 4 × 0.1000 ) / 2 (10^{-4}\times0.1000)/2 (10−4×0.1000)/2除以第一个方程然后减去第二个方程,则出现了用小数除以大数的现象,得
{ 1 0 − 4 × 0.1000 x 1 + 1 0 1 × 0.1000 x 2 = 1 0 1 × 0.1000 1 0 6 × 0.2000 x 2 = 1 0 6 × 0.2000 \begin{cases}10^{- 4}\times 0. 1000x_{1}+ 10^{1}\times 0. 1000x_{2}= 10^{1}\times 0. 1000\\10^{6}\times 0. 2000x_{2}= 10^{6}\times 0. 2000\end{cases} {10−4×0.1000x1+101×0.1000x2=101×0.1000106×0.2000x2=106×0.2000
由此解出 x 1 = 0 , x 2 = 1 0 1 × 0.1000 = 1 x_1=0,x_2=10^1\times0.1000=1 x1=0,x2=101×0.1000=1,显然严重失真
若反过来用第二个方程消去第一个方程中含 x 1 x_1 x1的项,则避免了大数被小数除的现象,得
{ 1 0 6 × 0.1000 x 2 = 1 0 6 × 0.1000 1 0 1 × 0.2000 x 1 + 1 0 1 × 0.1000 x 2 = 1 0 1 × 0.2000 \begin{cases}10^6\times0.1000x_2=10^6\times0.1000\\10^1\times0.2000x_1+10^1\times0.1000x_2=10^1\times0.2000\end{cases} {106×0.1000x2=106×0.1000101×0.2000x1+101×0.1000x2=101×0.2000
由此求得相当好的近似解 x 1 = 0.5000 , x 2 = 1 0 1 × 0.1000 。 x_1=0.5000,x_2=10^1\times0.1000。 x1=0.5000,x2=101×0.1000。