这里已知pi=16arctan1/5-4arctan1/239,要求运用arctanx幂级数展开式建立数值计算方法通过上式计算pi,并且误差小于10^-5.下面是我编写的一个程序,但运行不出结果,请高手纠正错误.高手们也可自己编写能运行的程序发来,不胜感激.arctanx幂级数展开式我就不写在这了.
#include<stdio.h>
#include<math.h>
double Arctan(double a,float x)
{
int i,s=1;
double d=0,d1=0,d2;
double y=0;
do
{
for(i=0;i<=30000;i++)
{ d2=d1;
y=pow(x,2*i-1);
d+=s*y/(double)(2*i-1);
s*=-1;
i++;
d1=s;
}
}while(fabs(d1-d2)>=1e-5);
return a*d1;
}
void main(){
double y1=0;
double y2=0;
double y3=0;
y1=Arctan(16,1/5);
printf("%lf",y1);
y2=Arctan(4,1/239);
y3=y1-y2;
printf("%lf",y3);}
#include<stdio.h>
#include<math.h>
double Arctan(double a,float x)
{
int i,s=1;
double d=0,d1=0,d2;
double y=0;
do
{
for(i=0;i<=30000;i++)
{ d2=d1;
y=pow(x,2*i-1);
d+=s*y/(double)(2*i-1);
s*=-1;
i++;
d1=s;
}
}while(fabs(d1-d2)>=1e-5);
return a*d1;
}
void main(){
double y1=0;
double y2=0;
double y3=0;
y1=Arctan(16,1/5);
printf("%lf",y1);
y2=Arctan(4,1/239);
y3=y1-y2;
printf("%lf",y3);}
可以啊,只要是有关的就行?请提供链接或直接发至邮箱[email protected]
追答内容很多,你可以直接通过百度搜索“猎豹网校”就可以了。