用4了四种方法,另外还加了个龙格贝.
大人大量给分吧~
#include
using namespace std;
double getPI0(int h){
double l = 1.0/h;
int i,j;
double s = 0;
for(i = 0; i < h; i++){
s += l*(4/(1+((2*i+1)*l/2)*((2*i+1)*l/2)));
}
return s;
}
double getPI1(double h){
double l = 1.0/h;
int i,j;
double s = 0;
for(i = 0; i < h; i++){
s += l*(4/((1+i*l*i*l)))/2+l*4/(1+((i+1)*l*(i+1)*l))/2;
}
return s;
}
double getPI2(double h){
double l = 1.0/h;
int i,j;
double a,b;
double s = 0;
for(i = 0; i < h; i++){
a = i*l;
b = i*l+l;
double fa = 4/(1+a*a);
double fb = 4/(1+b*b);
double fab = 4/(1+(a+b)*(a+b)/4);
s += l*(fa+4*fab+fb)/6;
}
return s;
}
double fj(double a,int j){
int i;
double r = 1;
for(i = 0; i < j; i++){
r *= a;
}
return r;
}
double longBeiGe(double r){//r为给定的误差限
double * tm;
double * t;
tm = new double[1];
t = new double [2];
tm[0] = getPI1(1);
t[0] = getPI1(2);
t[1] = (4*t[0]-tm[0])/3;
int i = 1,j = 0;
while(t[i]-tm[i-1]>r){
tm = t;i++;
t = new double [i+1];
t[0] = getPI1(fj(2,i+1));
for(j = 1; j
猜你喜欢
- 1有一个实心铝球,体积为1立方分米,把它放入水银中直至铝球处于静止,求铝球静止在水银中受到的浮力.
- 2You have no time on Sunday的反意疑问句是什么?
- 3临床上常给危重病人吸氧和点滴葡萄糖,请你用有关细胞的知识解释为什么要这样?
- 4计算:1乘3/1+3乘5/1……2007乘2009/1
- 5根据答句写出问句:(1)I am from China(2)Our English teacher is Miss White
- 6长方体的体积、表面积公式
- 7Could you recomend some English songs that are popular these days?
- 8初一英语→几个选词的适当形式、按句首字母填空,看看啦
- 9方程组3X+2Y=3 15X+5Y=-3 求XY的值是多少?
- 10以How do you spend your Spring Festival?为题写一篇英语作文,不少于60词.