アットウィキロゴ

正規

#include <stdio.h>
#include <math.h>
double f(double x,double mu,double sig){
double pi,x1,x2,x3,fx;
pi = 3.1415;
x1=-pow(x - mu,2) / (2*pow(sig,2));
x2=exp(x1);
x3=sig*pow(2*pi,0.5);
fx=x2/x3;
return fx;
}
double g(double y,double mu, double sig){
double gx,h,x;
int n,t;  
gx=0;
h=0.001;
t=floor(y/h);
for (n=-2000;n<t;n++){
x=n*h;
gx=gx+f(x,mu,sig)*h;
}
return gx;
}
double seeky(double p,double mu,double sig){
double g1,g2,y1,y2,y3;
int t;
y1=0.4;
y2=-0.2;
g1=g(y1,mu,sig);
t=0;
while(t<100){
g2=g(y2,mu,sig);
y3=y2+(p-g2)*(y2-y1)/(g2-g1);
y1=y2;
y2=y3;
g1=g2;
if (pow(p-g2,2)<0.0001)t=1000;
t=t+1;
}
return y2;
}

int main(void)
{
double p,mu,sig,yy;
double th[101];
int s;
mu=0;
sig=0.39;
for (s=1;s<101;s++){
p=0.01*s-0.005;
yy=seeky(p,mu,sig);
th[s]=exp(yy);
printf("%f",th[s]);
printf("\n");
}
return 0;
}
最終更新:2009年12月14日 17:50