向大神求助,最大似然法代码哪里出错了
#include<math.h>double f(double a,double b,double c)//f为概率函数
{double s;
s=0.399/sqrt(c)*exp(-(a-b)*(a-b)/2/c);
return(s);
}
double F(double a,double b,double c)
{int i;double j=0,S;
for(i=1;i<=10000;i++)
j+=f(i*a/10000,b,c);//F为分布函数
S=j*a/10000;
return(S);
}
#include<stdio.h>
#include<math.h>
double main()
{
double b,c,b1,c1,c2,w=0.0,h=0.0,x[200],y[20];
double p[10]={1,2,3,5,4,3,2,1,7,8},q[10]={0.5,0.6,0.8,0.3,0.4,0.9,0.4,0.5,0.8};
int i,j=0;
for (c=0.1;c<=2;c+=0.1)
{
c2=c;
for(b=1.0;b<=2.0;b=b+0.01)
{for(i=0;i<=9;i++)
w+=(f(p[i],b,c)-f(q[i],b,c))/(F(q[i],b,c)-F(p[i],b,c));
x[j++]=w;y[j++]=b;}
for(j=1;j<=99;j++)if(x[0]>=x[j]){x[0]=x[j];y[0]=y[j];}
b1=y[0];//printf("b1=%lf\n",y[0]);
for (c=0.1;c<=1.0;c+=0.1)
{for(i=0,j=0;i<=9;i++)
h+=((q[i]-b1)*f(q[i],b,c)-(p[i]-b1)*f(p[i],b,c))/(F(p[i],b,c)-F(q[i],b,c));
x[j++]=h;y[j++]=c;}
for(j=1;j<=9;j++)
if(x[0]>=x[j]){x[0]=x[j];y[0]=y[j];}
c1=y[0]; c=c2; // printf("c1=%lf\n",y[0]);
if(fabs(c1-c2)<=0.01)
printf("b1=%lf,c1=%lf\n",b1,c1);
//break;
}
}