アットウィキロゴ

zh

class pro{
public static void main(String args[]){
int s,t2;
double th[]=new double[11];
double w[]=new double[11];
double mu[]=new double[11];
double lam;
double alpha;
double c1,y1,u1,u2;
for (s=1;s<11;s++){
th[s]=1+0.1*s;
}

lam=fastlam(th);

alpha=0.5;

for (s=1;s<10;s++){
c1=1/lam;
y1=th[s+1]-1/lam;
u1=Math.log(c1)+Math.log(1-y1/th[s+1]);
c1=1/lam;
y1=th[s]-1/lam;
u2=Math.log(c1)+Math.log(1-y1/th[s+1]);
w[s]=u1+alpha*(u2-u1);
}

t2=0;
while(t2<1000){
for (s=1;s<10;s++){
mu[s]=seekmu(s,lam,w,th);
}

for (s=1;s<9;s++){
c1=(1-mu[s+1])/lam;
y1=seeky(s+1,lam,mu[s+1],th);
u1=Math.log(c1)+Math.log(1-y1/th[s+1]);
c1=(1-mu[s])/lam;
y1=seeky(s,lam,mu[s],th);
u2=Math.log(c1)+Math.log(1-y1/th[s+1]);
w[s]=u1+alpha*(u2-u1);
}
c1=1/lam;
y1=th[10]-1/lam;
u1=Math.log(c1)+Math.log(1-y1/th[10]);
c1=(1-mu[9])/lam;
y1=seeky(9,lam,mu[9],th);;
u2=Math.log(c1)+Math.log(1-y1/th[10]);
w[9]=u1+alpha*(u2-u1);
t2=t2+1;
}


for (s=1;s<10;s++){
c1=(1-mu[s])/lam;
y1=seeky(s,lam,mu[s],th);
System.out.println(c1);  
}
for (s=1;s<10;s++){
c1=(1-mu[s])/lam;
y1=seeky(s,lam,mu[s],th);
System.out.println(y1);  
}


}

static double seekmu(int s,double lam,double w[],double th[]){
double m1,m2,y1,c1,u1,mumu;
int t1;
mumu=0;
m1=0;
m2=0.4;
t1=0;
while(t1<10){
mumu=(m1+m2)/2;
y1=seeky(s,lam,mumu,th);
c1=(1-mumu)/lam;
u1=Math.log(c1)+Math.log(1-y1/th[s+1]);
if (u1>w[s])m1=mumu;
if (u1<w[s])m2=mumu;
t1=t1+1;
}
return mumu;
}

static double seeky(int s,double lam,double mumu,double th[]){
double y1,y2,y3,z3;
int t1;
y1=th[s]-1/lam;
y2=0.9*th[s];
y3=0;
t1=0;
while (t1<100){
y3=(y1+y2)/2;
z3=1/(y3-th[s])+lam+mumu/(th[s+1]-y3);
if (z3<0)y2=y3;
if (z3>0)y1=y3;
if (z3*z3<0.001)t1=1000;
t1=t1+1;
}
return y3;
}



static double fastlam(double th[]){
double la1,la2,la3;
double c1,y1,b1;
int s;
int t1;
la1=2;
la2=0.01;
la3=0;
t1=0;
while(t1<100){
la3=(la1+la2)/2;
b1=0;
for (s=1;s<11;s++){
c1=1/la3;
y1=th[s]-1/la3;
b1=b1+y1-c1;
}
if (b1>0)la1=la3;
if (b1<0)la2=la3;
if (b1*b1<0.0001)t1=1000;
t1=t1+1;
}
return la3;
}
}
最終更新:2010年06月28日 23:10