同样是求积分,为什么被积函数换了就不能运算了呢?
#include "math.h"double ffts(a,b,eps,f)
double a,b,eps,(*f)();
{ int n,k;
double fa,fb,h,t1,p,s,x,t;
fa=(*f)(a); fb=(*f)(b);
n=1; h=b-a;
t1=h*(fa+fb)/2.0;
p=eps+1.0;
while (p>=eps)
{ s=0.0;
for (k=0;k<=n-1;k++)
{ x=a+(k+0.5)*h;
s=s+(*f)(x);
}
t=(t1+h*s)/2.0;
p=fabs(t1-t);
t1=t; n=n+n; h=h/2.0;
}
return(t);
}
#include "stdio.h"
#include "9ffts.c"(w为以上函数文件名"9ffts.c")
main()
{ double a,b,eps,h,t1,t2,sum,fftsf(double);
a=0.0; b=1.0; eps=0.000001;
t1=ffts(a,b,eps,fftsf);
a=1.0; b=2.0; eps=0.000001;
t2=ffts(a,b,eps,fftsf);
sum=t1+t2;
printf("\n");
printf("sum=%e\n",sum);
printf("\n");
return 0;
}
#include "math.h"
double fftsf(x)
double x;
{ double y;
y=(x*x); (这里)
return(y);
}
当被积函数为y=x*x,结果为2.555556e+00
但被积函数为y=16.7*((2.0*(0.0003-0.5*x))/0.002-((0.0003-0.5*x)/0.002)*((0.0003-0.5*x)/0.002))怎么就不能算了呢?