我用C++写的龙贝格算法无法运行,请高手们帮忙看看
#include<iostream>#include<cmath>
using namespace std;
double f(double x);
double zt2(double,double,double,double);
double zs2(double,double);
double zc2(double,double);
double zr2(double,double);
const double e=0.00001;
int main()
{
double a,b,h,t1,t2,c1,c2,s1,s2,r1,r2;
int k;
k=1;
cout<<"please input a and b"<<endl;
cin>>a>>b;
h=b-a;
t1=h/2*(f(a)+f(b));
t2=zt2(t1,h,a,b);
s2=zs2(t2,t1);
k=k+1;
h=h/2;
t1=t2;
s1=s2;
t2=zt2(t1,h,a,b);
s2=zs2(t2,t1);
h=h/2;
c2=zc2(s2,s1);
c1=c2;
s1=s2;
t1=t2;
t2=zt2(t1,h,a,b);
s2=zs2(t2,t1);
c2=zc2(s2,s1);
r2=zr2(c2,c1);
k=k+1;
h=h/2;
r1=r2;
c1=c2;
s1=s2;
t1=t2;
t2=zt2(t1,h,a,b);
s2=zs2(t2,t1);
c2=zc2(s2,s1);
r2=zr2(c2,c1);
for(k=4;abs(r2-r1)<e;k++)
{
h=h/2;
r1=r2;
c1=c2;
s1=s2;
t1=t2;
t2=zt2(t1,h,a,b);
s2=zs2(t2,t1);
c2=zc2(s2,s1);
r2=zr2(c2,c1);
}
cout<<"r2 is"<<r2<<endl;
return 0;
}
double f(double x)
{
double z;
z=sin(x)/x;
return z;
}
double zt2(double t1,double h,double a,double b)
{
double s=0,T2;
for(a=a+h/2;a<b;a=a+h)
s=s+f(a);
T2=1/2*t1+h/2*s;
return T2;
}
double zs2(double T2,double T1)
{
double S2;
S2=T2+1/3*(T2-T1);
return S2;
}
double zc2(double S2,double S1)
{
double C2;
C2=S2+1/15*(S2-S1);
return C2;
}
double zr2(double C2,double C1)
{
double R2;
R2=C2+1/63*(C2-C1);
return R2;
}