标题:牛顿--科特斯公式-求积分-编译通过,可是逻辑上有错误了,老是得不到答案
只看楼主
梁朝斌
Rank: 4
等 级:业余侠客
帖 子:192
专家分:288
注 册:2012-10-21
结帖率:100%
 问题点数:0 回复次数:0 
牛顿--科特斯公式-求积分-编译通过,可是逻辑上有错误了,老是得不到答案
#include<stdio.h>
#include<math.h>
#define maxsize 100
#define eps 0.000001
int main(void)
 {
     double a,b,t,x[maxsize],step,s0,s1;
     double m1,m2,m3,sum1,sum2,sum3,sum4;
     double f(double m);
     int i,n;
     printf("请输入积分下限:\n");
     scanf("%lf",&a);
     printf("请输入积分上限:\n");
     scanf("%lf",&b);
 
     n=0;
     s0=0;
     do
     {
         n=n+1;
         step=(b-a)/n;
         for(i=0;i<=n;i++)
             x[i]=a+i*step;
         sum1=sum2=sum3=sum4=1;
         for(i=0;i<=n-1;i++)
         {
             m1=x[i]+(x[i+1]-x[i])/4;
             sum1+=f(m1);
         }
         for(i=0;i<=n-1;i++)
         {
             m2=x[i]+(x[i+1]-x[i])/2;
             sum2+=f(m2);
         }
         for(i=0;i<=n-1;i++)
         {
             m3=x[i]+(x[i+1]-x[i])*3/4;
             sum1+=f(m1);
         }
         for(i=0;i<=n-1;i++)
         {
             sum2+=f(x[i]);
         }
         s1=0;
         s1+=(7*(f(a)+f(b))+32*sum1+12*sum2+32*sum3+14*sum4)*step/90;
         t=s0;
         s0=s1;
     }

     while (fabs(s0-t)>eps&&n<100);
     {
         printf("s0=%lf\n",s0);
         printf("此时步长为:%d",n);
         printf("\n");
     }
     return 0;
 }
 double f(double c)
 {
     double y;
     y=sqrt(1+pow(c,2));
     return y;
 }
     
搜索更多相关主题的帖子: double 积分 include 
2012-12-09 14:14



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-390280-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.092372 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved