|
楼主 |
发表于 2005-9-17 18:43:34
|
显示全部楼层
<>include<stdio.h>///////////////// 适合第一题<BR>#include<math.h><BR>#define N 1000</P>
<>double f(double x)<BR>{ return pow(x,-2);}</P>
<>double zhongzhi(double a,double h,int n1)<BR>{double m=0.0;<BR> int k;<BR> for(k=0;k<=n1;k++)<BR> m=m+f((k*h+a+(k+1)*h+a)/2);<BR>return m;}</P>
<P><BR>double pow1(int k,int r)<BR> { <BR>int f=1,i;<BR>for(i=0;i<r;i++)<BR>f*=k;<BR>return f;<BR>}<BR> <BR>double longbg(double a,double b,double e )<BR>{ long int n=1;<BR>int i,j,p,q;<BR>double h=0.0,m1=0.0,g[N][N]={0};<BR> h=b-a; <BR>g[0][0]=h/2*(f(a)+f(b)); <BR>for(i=1;i<N;i++)<BR> { g[0]=(double)1/2*g[i-1][0]+h/2*zhongzhi(a,h,n-1); </P>
<P> <BR> for(j=1;j<=i;j++)<BR> <BR> g[j]=pow1(4,j)/(pow1(4,j)-1)*g[j-1]-1/(pow1(4,j)-1)*g[i-1][j-1];<BR> <BR> <BR> <BR> n*=2;<BR> <BR> h=(double)(b-a)/n;<BR> <BR> <BR> <BR> <BR> if(fabs(g-g[i-1][i-1])<e) break; <BR> p=i;q=j;<BR> <BR> }<BR> /* printf("龙贝格矩阵为:\n");<BR> for(i=0;i<=p;i++){<BR> printf("\n");<BR> for(j=0;j<=i;j++)<BR> printf(" %.7lf",g[j]);}<BR> <BR> printf("\n满意 积分的值为 :%.7lf\n",g[p][q-1]);*/<BR>m1=g[p][q-1];<BR> return m1;<BR>}</P>
<P>void main()<BR>{<BR>int i,n2;</P>
<P><BR>double a,b,h=0.0,e=0.0,len=0.0,T=0.0;</P>
<P>printf("请输入所满意积分的下界和误差极限:A,e:");<BR>scanf("%lf%lf",&a,&e);<BR>printf("输入DVD 的个数N2和 类别 len:\n");<BR>scanf("%d %lf",&n2,&len);<BR> printf("所输入的日期 初始点为=%lf 分周期 为 = %d",a,n2); <BR> <BR> <BR> b=a+len;<BR>for(i=1;i<=n2;i++)<BR>{T=T+longbg(a,b,e);<BR> a=b;<BR> b=a+len;<BR>if(f(b)<e)break;<BR>}<BR>printf(" 所求的满意度常积分为: %lf",T);</P> |
|