编一个C语言程序--求f(x)在a,b上的定积分

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/30 00:23:58

编一个C语言程序--求f(x)在a,b上的定积分
编一个C语言程序--求f(x)在a,b上的定积分

编一个C语言程序--求f(x)在a,b上的定积分
//---------------------------------------------------------------------------
#include
#include
double f(double x)
{
double y;
y=log(x); /*f(x)的定义,可自行修改*/
return y;
}
double simp(double a,double b,const double eps,double (*f)(double))
/*利用simpson公式求f(x)的定积分*/
{
int n=1,k;
double h,t1,t2,s1,s2,ep,p,x;
if (a-b>0) {
x=a;
a=b;
b=x;
}
h=b-a;
t1=h*((*f)(a)+(*f)(b))/2.0;
s1=t1;
ep=eps+1.0;
while (ep>=eps)
{
p=0.0;
for (k=0; k