标题:请教floating point error: domain!奇怪!
只看楼主
xiaolaopo
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2008-7-31
 问题点数:0 回复次数:0 
请教floating point error: domain!奇怪!
#include "math.h"
double ffts(a,b,eps,f)
double a,b,eps,(*f)();
{ int n,k;
double fa,fb,h,t1,p,s,x,t;
fa=(*f)(a); fb=(*f)(b);
n=1; h=b-a;
t1=h*(fa+fb)/2.0;
p=eps+1.0;
while (p>=eps)
{ s=0.0;
for (k=0;k<=n-1;k++)
{ x=a+(k+0.5)*h;
s=s+(*f)(x);
}
t=(t1+h*s)/2.0;
p=fabs(t1-t);
t1=t; n=n+n; h=h/2.0;
}
return(t);
}

#include "stdio.h"
#include "9ffts.c" (9ffts.c为上面函数文件名)
float e,z ;
main()
{ int i;
float a,eps,k,h;
float xx1,xx2,b;
float a12,b12,t12,h0,sum,fftsf(float);
scanf("%f,%f",&e,&k);
h0=315.0;
xx1=300.00;
xx2=-300.00;
for(i=0; ;i++)
{
z=e/(k*h0);
a=0.0; b=k*h0; eps=0.000001;
sum=ffts(a,b,eps,fftsf);
if((e<=0.0033)&&(e>0.0))
{if((sum>=xx2)&&(sum<=xx1))
{printf("z= %e\n,sum= %e\n k= %f\n",z,sum,k);
break;
}
if(sum<xx2)
k=k+0.0001;
if(sum>xx1)
k=k-0.0001;
}
else break;
}
return 0;
}



#include "math.h"
float fftsf(float x)
{
float y;
if((e<=0.002)&&(e>=0.0))
y=16.7*((2.0*(e-z*x))/0.002-((e-z*x)/0.002)*((e-z*x)/0.002));
else if((e<=0.0033)&&(e>=0.002))
y=16.7*((1.0-0.15*((e-z*x)-0.002)/0.0013));
else y=0;
return y;
}

当输入0.0001,0.5时,输出正确结果;
但当输入0.003,0.5时,显示floating point error: domain!在调试的时候发现循环语句是在循环,可是为什么最后就输不出结果呢?而显示floating point error: domain!
搜索更多相关主题的帖子: domain point floating 
2008-08-03 08:30



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




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

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