アットウィキロゴ

対数

#include <stdio.h>
#include <math.h>
double g(double y,double mu, double sig){
double g1,g2,h,x,x1,x2,x3,f;
int n,t;
double pi;
pi = 3.1415;
g1=0;
h=0.001;
t=floor(y/h);
for (n=-2000;n<t;n++){
x=n*h;
x1=-pow(x - mu,2) / (2*pow(sig,2));
x2=exp(x1);
x3=sig*pow(2*pi,0.5);
g2=x2/x3;
g1=g1+g2*h;
}
return g1;
}
int main(void)
{
double y1,y2,y3,g1,g2,p,mu,sig;
double th[101];
int t,s;
mu=0;
sig=0.39;
for (s=1;s<101;s++){
p=-0.005+0.01*s;
y1=-0.4;
y2=0.3;
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;
}
th[s]=exp(y2);
printf("%f",th[s]);
printf("\n");
}
return 0;
}
最終更新:2009年12月14日 11:08