数值分析PTA第一题
来源:互联网 发布:淘宝客新建推广位 编辑:程序博客网 时间:2024/05/16 16:21
请数值分析课的同学切勿直接使用代码提交,谢谢
Produce a table of the values of the series
for the 3001 values of xx, xx = 0.0, 0.1, 0.2, …, 300.00. All entries of the table must have an absolute error less than
. This problem is based on a problem from Hamming (1962), when mainframes were very slow by today’s microcomputer standards.
void Series_Sum( double sum[] );
where double sum[]
is an array of 3001 entries, each contains a value of
#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 */
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
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.
这题和ZOJ_1007题很像,只是ZOJ_1007题的取值为0-2,如果此题按照ZOJ_1007的来,先减去
/*author ZJU_Nor-His*/#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;}void Series_Sum(double sum[]){ int i = 0; double j = 0; int xy; double sum_index = 0.0; double x = 0.0; for (i = 1; i < 301; i++) { sum_index = 0.0; for (j = 1; j <=i; j++) { sum_index += 1.0 / j; } sum[i * 10] = sum_index/i; } for (i = 0; i < 3001; i++) { sum_index = 0.0; if (i == 0||i%10!=0) { if (i < 2980) { xy = i/10 + 1; } else { xy = i/10-1; } for (j = 1; j < 1500; j++) { sum_index += 1.0 / (j*(j + xy)*(j + xy + 1)*(j+x)*(j + xy + 2)); } sum[i] = (xy - x)*((xy - x+ 1)*(sum_index*(xy-x+2)+(sum[xy*10]+sum[xy*10+20]-2*sum[xy*10+10])/2) + sum[xy*10] - sum[xy*10 + 10]) + sum[xy*10]; } x += 0.1; } return;}
- 数值分析PTA第一题
- 2015年清华大学高等数值分析(李津)第一次数值实验
- 数值分析
- 数值分析
- 数值分析
- 数值分析
- 数值分析
- PTA 4-2 奇数值结点链表 (50分)
- PTA
- PTA
- pta
- pta
- 数值分析第三章上机实习题
- 数值分析第四章上机实习题
- 数值分析与PCB
- MyTDMA 数值分析P183
- 数值分析,你大爷
- 数值分析之龙贝格求积法
- 100. Same Tree
- 关于tableview性能的优化及卡顿现象
- 第三天数据库 事务 listview
- Oracle 11g RAC客户端使用SCAN IP无法连接问题
- ubuntu安装vpn PPTP
- 数值分析PTA第一题
- 14. MVC
- 归并排序(Merge Sort)
- html DOM和xml DOM的区别于联系
- Codeforces 651C - Watchmen
- Python与硬件学习笔记:蓝牙(二)
- JS初步学习
- 项目1-宣告“主权”
- 213. House Robber II LeetCode