117.求定积分

#include "stdio.h"
#include "math.h"


double fsimpf(x) /*要进行计算的被积函数*/
double x;
{
	double y;
    y=log(1.0+x)/(1.0+x*x);
    return(y);
}

double fsimp(a,b,eps) /*辛普森算法*/
double a,b,eps; /*a为积分下限,b为积分上限,eps是希望达到的精度*/
{
    int n,k;
    double h,t1,t2,s1,s2,ep,p,x;
    n=1; h=b-a;
    t1=h*(fsimpf(a)+fsimpf(b))/2.0;  /*用梯形公式求出一个大概的估值*/
    s1=t1;
    ep=eps+1.0;
    while (ep>=eps)
	{
		/*用梯形法则计算*/
		p=0.0;
		for (k=0;k<=n-1;k++)
		{
			x=a+(k+0.5)*h;
			p=p+fsimpf(x);
		}
		t2=(t1+h*p)/2.0;
		/*用辛普森公式求精*/
		s2=(4.0*t2-t1)/3.0;
		ep=fabs(s2-s1);
		t1=t2; s1=s2; n=n+n; h=h/2.0;
	}
    return(s2);
}
main()
{
	double a,b,eps,t;
        a=0.0; b=1.0; eps=0.0000001;
    	clrscr();
	puts("**********************************************************");
	puts("*         This program is to calculat the Value of       *");
	puts("*          a definite integral by Simpson Method.        *");
	puts("**********************************************************");
    	t=fsimp(a,b,eps);
	puts("\n----------------------------------------------------------");
	printf(" >> The result of definite integral is : \n");
	printf(" >> SIGMA(0,1)ln(1+x)/(1+x^2)dx = ");
    	printf("%e\n",t);
    	puts("----------------------------------------------------------");
    	printf("\n Press any key to quit...");
	getch();
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

编程与实战

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值