6-1 Numerical Summation of a Series (40分)

Produce a table of the values of the series
or the 3001 values of x, x = 0.0, 0.1, 0.2, …, 300.00. All entries of the table must have an absolute error less than 10​−10
​​ . This problem is based on a problem from Hamming (1962), when mainframes were very slow by today’s microcomputer standards.
Format of function:
void Series_Sum( double sum[] );
where double sum[] is an array of 3001 entries, each contains a value of ϕ(x) for x = 0.0, 0.1, 0.2, …, 300.00.
Sample program of judge:

#include <stdio.h>

void Series_Sum( double sum[] );

int main()
{
    int i;
    double x, sum[3001];
	
    Series_Sum( sum );

    x = 0.0;
    for (i=0; i<3001; i++)
        printf("%6.2f %16.12f\n", x + (double)i * 0.10, sum[i]);

    return 0;
}

/* Your function will be put here */
Sample Output:
0.00   1.644934066848
0.10   1.534607244904
...
1.00   1.000000000000
...
2.00   0.750000000000
...
300.00   0.020942212934

Hint:
The problem with summing the sequence in equation (1) is that too many terms may be required to complete the summation in the given time. Additionally, if enough terms were to be summed, roundoff would render any typical double precision computation useless for the desired precision.

To improve the convergence of the summation process note that
which implies ϕ(1)=1.0. One can then produce a series for ϕ(x)−ϕ(1) which converges faster than the original series. This series not only converges much faster, it also reduces roundoff loss.

This process of finding a faster converging series may be repeated again on the second series to produce a third sequence, which converges even more rapidly than the second.

The following equation is helpful in determining how may items are required in summing the series above.

解法:

  1. 注意到当x是整数时, ϕ ( x ) = ∑ i = 1 x 1 i \phi(x)=\sum\limits_{i=1}^x\frac{1}i ϕ(x)=i=1xi1
  2. 需要用公式将x不是整数的情况收敛到整数。
    ϕ ( x ) − ϕ ( i ) = ∑ i − x k ( k + x ) ( k + i ) \phi(x)-\phi(i)=\sum\frac{i-x}{k(k+x)(k+i)} ϕ(x)ϕ(i)=k(k+x)(k+i)ix

∑ 1 k ( k + x ) ( k + i ) = ∑ k + x + i + 1 − x k ( k + x ) ( k + i ) ( k + i + 1 ) = ∑ 1 k ( k + i ) − ∑ i + 1 − x k ( k + x ) ( k + i ) ( k + i + 1 ) = ϕ ( i ) − ( i + 1 − x ) ∑ 1 k ( k + x ) ( k + i ) ( k + i + 1 ) \sum\frac{1}{k(k+x)(k+i)}=\sum\frac{k+x+i+1-x}{k(k+x)(k+i)(k+i+1)}=\sum\frac{1}{k(k+i)}-\sum \frac{i+1-x}{k(k+x)(k+i)(k+i+1)}=\phi(i)-(i+1-x)\sum \frac{1}{k(k+x)(k+i)(k+i+1)} k(k+x)(k+i)1=k(k+x)(k+i)(k+i+1)k+x+i+1x=k(k+i)1k(k+x)(k+i)(k+i+1)i+1x=ϕ(i)(i+1x)k(k+x)(k+i)(k+i+1)1

∑ 1 k ( k + x ) ( k + i ) ( k + i + 1 ) = ∑ k + x + i + 2 − x k ( k + x ) ( k + i ) ( k + i + 1 ) ( k + i + 2 ) = ∑ i + 2 − x k ( k + x ) ( k + i ) ( k + i + 1 ) ( k + i + 2 ) + ∑ 1 k ( k + i ) ( k + i + 1 ) ( k + i + 2 ) \sum \frac{1}{k(k+x)(k+i)(k+i+1)}=\sum\frac{k+x+i+2-x}{k(k+x)(k+i)(k+i+1)(k+i+2)}=\sum\frac{i+2-x}{k(k+x)(k+i)(k+i+1)(k+i+2)}+\sum\frac{1}{k(k+i)(k+i+1)(k+i+2)} k(k+x)(k+i)(k+i+1)1=k(k+x)(k+i)(k+i+1)(k+i+2)k+x+i+2x=k(k+x)(k+i)(k+i+1)(k+i+2)i+2x+k(k+i)(k+i+1)(k+i+2)1
其中

∑ 1 k ( k + i ) ( k + i + 1 ) ( k + i + 2 ) = 1 2 ( ∑ 1 k ( k + i ) ( k + i + 1 ) − ∑ 1 k ( k + i + 1 ) ( k + i + 2 ) ) = 1 2 ( ϕ ( i ) − ϕ ( i + 1 ) − ( ϕ ( i + 1 ) − ϕ ( i + 2 ) ) ) \sum\frac{1}{k(k+i)(k+i+1)(k+i+2)}=\frac12(\sum\frac{1}{k(k+i)(k+i+1)}-\sum\frac{1}{k(k+i+1)(k+i+2)})=\frac12(\phi(i)-\phi(i+1)-(\phi(i+1)-\phi(i+2))) k(k+i)(k+i+1)(k+i+2)1=21(k(k+i)(k+i+1)1k(k+i+1)(k+i+2)1)=21(ϕ(i)ϕ(i+1)(ϕ(i+1)ϕ(i+2)))

可得收敛式:
ϕ ( x ) = ϕ ( i ) + ( i − x ) ( ϕ ( i ) − ( i + 1 − x ) ( ∑ i + 2 − x k ( k + x ) ( k + i ) ( k + i + 1 ) ( k + i + 2 ) + 1 2 ϕ ( i ) − ϕ ( i + 1 ) + 1 2 ϕ ( i + 2 ) ) ) ) \phi(x)=\phi(i)+(i-x)(\phi(i)-(i+1-x)(\sum\frac{i+2-x}{k(k+x)(k+i)(k+i+1)(k+i+2)}+\frac12\phi(i)-\phi(i+1)+\frac12\phi(i+2)))) ϕ(x)=ϕ(i)+(ix)(ϕ(i)(i+1x)(k(k+x)(k+i)(k+i+1)(k+i+2)i+2x+21ϕ(i)ϕ(i+1)+21ϕ(i+2))))

提供一种具体算法的思路:

  1. 外循环计算 ϕ ( i ) \phi(i) ϕ(i)
  2. 内循环计算 x x x i i i i + 1 i+1 i+1时的 ϕ ( x ) \phi(x) ϕ(x)
  3. 计算1000项精度即可满足条件
  4. 积分式是用来估算项数的,不是用来算n到无穷的值的,n以后的值可忽略。

上代码

double phi(int x) {
    double ret = 0.0;
    for (int i = 1; i <= x; i++) {
        ret += 1.0 / i;
    }
    return ret / (double)x;
}
void Series_Sum(double sum[]) {
    int n = 1000;
    sum[0] = 1.644934066848;
    for (int i = 0; i < 300; i++) {
        double phii = phi(i + 1);
        double phii1 = phi(i + 2);
        double phii2 = phi(i + 3);
        for (int j = 1; j <= 10; j++) {
            int x = 10*i + j;
            double dx = x * 0.1;
            sum[x] = 0;// ((double)i + 3.0 - dx) / (4.0 * (double)n * (double)n * (double)n * (double)n);
            for (int k = 1; k < n; k++) {
                sum[x] += 1.0 / ((double)k * ((double)k + dx) * ((double)k + (double)i + 1.0) * ((double)k + (double)i + 2.0) * ((double)k + (double)i + 3.0));
            }
            sum[x] = phii + ((double)i + 1.0 - dx) * (((double)i + 2.0 - dx) * (((double)i + 3.0 - dx) * sum[x] + 0.5 * phii - phii1 + 0.5 * phii2) + phii - phii1);
        }
    }
}
ZJU_Main 主页 下一页 ZJU 题型类 文演整理版 2008-3-23 数论: 1007 Numerical Summation of a Series 简单题,还是蛮有意思的 1045 HangOver 简单题 1049 I Think I Need a Houseboat 简单题 1028 Flip and Shift 简单题,可以DP/BFS/……,但是实际上有数学方法可直接判断出来 1026 Modular multiplication of polynomials 简单题,有比较简单的好算法 1307 Packets 简单题,不过也蛮经典的…… 1312 Prime Cuts 简单题 1334 Basically Speaking 简单题 1337 Pi 简单题 1342 Word Index 简单题 1349 Four Quarters 简单题 1350 The Drunk Jailer 简单题 1352 Number Base Conversion 简单题 1353 Unimodal Palindromic Decompositions 规模不大,所以是简单题…… 1354 Extended Lights Out 简单题 1362 Game Prediction 简单题 1365 Mileage Bank 简单题 1382 A Simple Task 简单题 1383 Binary Numbers 简单题 1403 Safecracker 简单题 1408 The Fun Number System 简单题 1486 Color the Tree 简单题 1487 Playing Cards 简单题 1489 2^x mod n = 1 简单题,应该有好算法,不过枚举就可以过…… 1503 One Person "The Price is Right" 简单题,POI Eggs的翻版 1512 Water Treatment Plants 简单题,组合计数 1526 Big Number 简单题,不过O(1)和O(n)还是有区别的:) 1529 Enigmatic Travel 简单题,不过个人感觉题目描述很令人费解 1530 Find The Multiple 简单题 1537 Playing with a Calculator 简单题 1577 GCD & LCM 简单题,区联赛的题…… 1005 Jugs 简单题 1543 Stripies 简单题 1569 Partial Sums 简单题 1062 Trees Made to Order 简单题 1070 Bode Plot 简单题 1073 Round and Round We Go 简单题,142857,我喜欢^_^ 1078 Palindrom Numbers 简单题 1086 Octal Fractions 简单题 1199 Point of Intersection 简单题 1104 Leaps Tall Buildings 简单题 1110
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值