浮点数累加误差

Question:

The floating point sum of x + y x+y x+y has a relative error ϵ < ϵ m \epsilon < \epsilon_{m} ϵ<ϵm. ϵ m \epsilon_{m} ϵm is the machine epsilon.

double compute_sum(double x[], int n)
{
	double S = 0;
	for (int i = 0; i < n; ++i)
	S += x[i];
	return S;
}

Show that the absolute error in the sum computed in the above code is no worse than ( n − 1 ) ⋅ ϵ m ∑ i = 0 n − 1 ∣ x i ∣ (n-1)\cdot \epsilon_{m}\sum_{i=0}^{n-1}|x_i| (n1)ϵmi=0n1xi.

Answer:

S = x 0 + x 1 + … + x n − 1 S=x_0+x_1+\ldots+x_{n-1} S=x0+x1++xn1

Considering the error ϵ \epsilon ϵ , let:

S 0 = ( x 0 + x 1 ) ⋅ ( 1 + ϵ 0 ) S_0 = (x_0+x_1)\cdot(1+\epsilon_0) S0=(x0+x1)(1+ϵ0)

S 1 = ( S 0 + x 2 ) ⋅ ( 1 + ϵ 1 ) S_1 =(S_0+x_2)\cdot(1+\epsilon_1) S1=(S0+x2)(1+ϵ1)

S 2 = ( S 1 + x 3 ) ⋅ ( 1 + ϵ 2 ) S_2=(S_1+x_3)\cdot(1+\epsilon_2) S2=(S1+x3)(1+ϵ2)

⋮ \vdots

S n − 2 = ( S n − 3 + x n − 1 ) ⋅ ( 1 + ϵ n − 2 ) S_{n-2} = (S_{n-3}+x_{n-1})\cdot(1+\epsilon_{n-2}) Sn2=(Sn3+xn1)(1+ϵn2)

Considering S 0 S_0 S0 & S 1 S_1 S1, we have:

S 0 = ( x 0 + x 1 ) ⋅ ( 1 + ϵ 0 ) = ( x 0 + x 1 ) + ( x 0 + x 1 ) ⋅ ϵ 0 \begin{aligned} S_0 &= (x_0+x_1)\cdot(1+\epsilon_0) \\ &=(x_0+x_1)+(x_0+x_1)\cdot\epsilon_0 \end{aligned} S0=(x0+x1)(1+ϵ0)=(x0+x1)+(x0+x1)ϵ0

S 1 = ( S 0 + x 2 ) ⋅ ( 1 + ϵ 1 ) = ( ( x 0 + x 1 + x 2 ) + ( x 0 + x 1 ) ⋅ ϵ 0 ) ( 1 + ϵ 1 ) = ( x 0 + x 1 + x 2 ) + ( x 0 + x 1 ) ⋅ ϵ 0 + ( x 0 + x 1 + x 2 ) ϵ 1 + ( x 0 + x 1 ) ⋅ ϵ 0 ⋅ ϵ 1 = ( x 0 + x 1 + x 2 ) + ( x 0 + x 1 ) ⋅ ϵ 0 + ( x 0 + x 1 + x 2 ) ϵ 1 \begin{aligned} S_1 &=(S_0+x_2)\cdot(1+\epsilon_1) \\ &=((x_0+x_1+x_2)+(x_0+x_1)\cdot\epsilon_0)(1+\epsilon_1) \\ &=(x_0+x_1+x_2)+(x_0+x_1)\cdot\epsilon_0 +(x_0+x_1+x_2)\epsilon_1+(x_0+x_1)\cdot\epsilon_0\cdot\epsilon_1 \\ &= (x_0+x_1+x_2)+(x_0+x_1)\cdot\epsilon_0 +(x_0+x_1+x_2)\epsilon_1\end{aligned} S1=(S0+x2)(1+ϵ1)=((x0+x1+x2)+(x0+x1)ϵ0)(1+ϵ1)=(x0+x1+x2)+(x0+x1)ϵ0+(x0+x1+x2)ϵ1+(x0+x1)ϵ0ϵ1=(x0+x1+x2)+(x0+x1)ϵ0+(x0+x1+x2)ϵ1

Hence,

S n − 2 − S = x 0 ⋅ ( ϵ 0 + … + ϵ n − 2 ) + x 1 ⋅ ( ϵ 0 + … + ϵ n − 2 ) + x 2 ⋅ ( ϵ 1 + … + ϵ n − 2 ) + … + x ( n − 1 ) ⋅ ϵ n − 2 < ∣ x 0 ∣ ⋅ ( ϵ 0 + … + ϵ n − 2 ) + ∣ x 1 ∣ ⋅ A + … + ∣ x n − 1 ∣ ⋅ A < ∣ x 0 ∣ ⋅ ( ( n − 1 ) ϵ m ) + ∣ x 1 ∣ ⋅ B + … + ∣ x n − 1 ∣ ⋅ B = ( n − 1 ) ⋅ ϵ m ⋅ ∑ i = 0 n − 1 ∣ x i ∣ \begin{aligned} S_{n-2}-S &= x_0\cdot(\epsilon_0+\ldots+\epsilon_{n-2})+x_1\cdot(\epsilon_0+\ldots+\epsilon_{n-2}) \\ &+x_2\cdot(\epsilon_1+\ldots+\epsilon_{n-2})+\ldots+x(n-1)\cdot\epsilon_{n-2} \\ &<|x_0|\cdot(\epsilon_0+\ldots+\epsilon_{n-2})+|x_1|\cdot A+\ldots+|x_{n-1}|\cdot A \\ &< |x_0|\cdot((n-1)\epsilon_m)+|x_1|\cdot B+\ldots+|x_{n-1}|\cdot B \\&= (n-1)\cdot\epsilon_m\cdot\sum_{i=0}^{n-1}|x_i|\end{aligned} Sn2S=x0(ϵ0++ϵn2)+x1(ϵ0++ϵn2)+x2(ϵ1++ϵn2)++x(n1)ϵn2<x0(ϵ0++ϵn2)+x1A++xn1A<x0((n1)ϵm)+x1B++xn1B=(n1)ϵmi=0n1xi

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值