yflll 发表于 2005-12-28 13:56

高手,高手,高高手!

<P>#include&lt;STDIO.H&gt;<BR>#include&lt;CONIO.H&gt;<BR>#include&lt;MATH.H&gt;<BR>main()<BR>{<BR> int i=1,n=4;<BR> double xm;<BR> float t=0.0;<BR> float f(float x,float t);<BR> float Simpson(float(*f)(float,float),float,float,int);<BR> for(t=0.0;t&lt;=2.0;i++)<BR> {<BR>xm=Simpson(f,0.0,t,n);<BR>printf("x(%f)=%lf\n",t,xm);<BR>xm=0.0;<BR>t=t+0.025;<BR>n=n*(i+1);<BR> }</P>
<P>}</P>
<P>float Simpson(float (*f)(float x,float t),float a,float b,int n)<BR>{<BR> int k;<BR> float s,s1,s2=0.0;<BR> float h=(b-a)/n;<BR> s1=f(a+h/2,b);<BR> for(k=1;k&lt;=n-1;k++)<BR> {<BR>s1=s1+f(a+k*h,b);<BR>s2=s2+f(a+k*h,b);<BR> }<BR> s=h/6*(f(a,b)+4*s1+2*s2+f(b,b));<BR> return s;<BR>}</P>
<P><BR>float f(float x,float t)<BR>{<BR>return sin(10*x)*exp(1.25(x-t))*sin(24.968730*(t-x))*(25000/24968.730444);<BR>}<BR><BR><BR>各位高手,看看我的程序问题出在哪?<BR>我是利用辛普森求积公式求解,sin(10*x)*exp(1.25(x-t))*sin(24.968730*(t-x))*(25000/24968.730444);在(0,t)上的积分,t的取值只能计算十五次,就提示我:floating point error;Divide by 0<BR>这是怎么回事?请高手指点!!!<BR></P>

yflll 发表于 2005-12-28 15:34

<P>没人呢?</P>

Silence 发表于 2005-12-28 15:58

<P>不是高手,斗胆一试,建议搂主以后提问用务实一点的方法,呵呵,把想帮忙的同志都吓跑了<BR>#include&lt;STDIO.H&gt;<BR>#include&lt;CONIO.H&gt;<BR>#include&lt;MATH.H&gt;<BR>void main()<BR>{<BR> int i=1,n=50;<BR> double xm;<BR> double t=0.0;<BR> double f(double x,double t);<BR> double Simpson(double(*f)(double,double),double,double,int);<BR> for(t=0.0;t&lt;=2.0;i++)<BR>{<BR>    n = 50;<BR>    xm=Simpson(f,0.0,t,n);<BR>    printf("%d\n",i);<BR>    printf("x(%f)=%lf\n",t,xm);<BR>    xm=0.0;<BR>    t=t+double(0.025);<BR>    n=n*(i+1);<BR>}<BR>}<BR>double Simpson(double (*f)(double x,double t),double a,double b,int n)<BR>{<BR> int k;<BR> double s,s1,s2=0.0;<BR> double h=(b-a)/n;<BR> s1=f(a+h/2,b);<BR> for(k=1;k&lt;=n-1;k++)<BR> {<BR>   s1=s1+f(a+k*h,b);<BR>   s2=s2+f(a+k*h,b);<BR> }<BR> s=h/6*(f(a,b)+4*s1+2*s2+f(b,b));<BR> return s;<BR>}</P>
<P><BR>double f(double x,double t)<BR>{ <BR> double temp;<BR> temp = sin(10*x)*exp(1.25*(x-t));<BR> temp = temp*sin(24.968730*(t-x))*(25000/24968.730444);<BR> return temp;<BR>}<BR>现在都能算过去了,结果自己找别的数学软件比较吧。</P>

lang473036 发表于 2006-4-30 11:03

<P>我不知道你到底想干什么??但是我把你的程序用VC++运行了一下修正一错误可以运行了啊<BR>#include&lt;STDIO.H&gt;<BR>#include&lt;CONIO.H&gt;<BR>#include&lt;MATH.H&gt;<BR>main()<BR>{<BR>int i=1,n=4;<BR>double xm;<BR>float t=0.0;<BR>float f(float x,float t);<BR>float Simpson(float(*f)(float,float),float,float,int);<BR>for(t=0.0;t&lt;=2.0;i++)<BR>{<BR>xm=Simpson(f,0.0,t,n);<BR>printf("x(%f)=%lf\n",t,xm);<BR>xm=0.0;<BR>t=t+0.025;<BR>n=n*(i+1);<BR>}<BR>return 0;<BR>}</P>
<P>float Simpson(float (*f)(float x,float t),float a,float b,int n)<BR>{<BR>int k;<BR>float s,s1,s2=0.0;<BR>float h=(b-a)/n;<BR>s1=f(a+h/2,b);<BR>for(k=1;k&lt;=n-1;k++)<BR>{<BR>s1=s1+f(a+k*h,b);<BR>s2=s2+f(a+k*h,b);<BR>}<BR>s=h/6*(f(a,b)+4*s1+2*s2+f(b,b));<BR>return s;<BR>}</P>
<P><BR>float f(float x,float t)<BR>{<BR>return sin(10*x)*exp(1.25*(x-t))*sin(24.968730*(t-x))*(25000/24968.730444);<BR>}<BR></P>
页: [1]
查看完整版本: 高手,高手,高高手!