package linear;
class pro{
int s;
double th[]= new double[101];
double tl,tr,w1;
double c1,y1;
public static void main(String args[]){
pro test=new pro();
}
pro(){
for (s=1;s<101;s++){
th[s]=0.02*s;
}
tl=tls(th);
tr=trs(tl,th);
for (s=1;s<101;s++){
y1=th[s]*lx(s,tl,tr,th);
c1=tr+(1-tl)*y1;
System.out.println(c1);
}
}
double lx(int s,double tl,double tr,double th[]){
double w1,l1;
w1=(1-tl)*th[s];
l1=(w1-tr)/(2*+w1);
if (l1<0)l1=0;
return l1;
}
double bud(double tl,double tr,double th[]){
double c1,y1,b1;
int s;
b1=0;
for (s=1;s<101;s++){
y1=th[s]*lx(s,tl,tr,th);
c1=(1-tl)*y1+tr;
b1=b1+y1-c1;
}
return b1;
}
double trs(double tl,double th[]){
double tr1,tr2,tr3,b1,b2;
int t;
tr1=0.1;
tr2=0.2;
b1=bud(tl,tr1,th);
t=0;
while(t<100){
b2=bud(tl,tr2,th);
tr3=tr2-b2*(tr2-tr1)/(b2-b1);
tr1=tr2;
tr2=tr3;
b1=b2;
if (b2*b2<0.0001)t=1000;
t=t+1;
}
return tr2;
}
double tls(double th[]){
int m;
double tl,tr,w1,maxw,maxtl;
maxw=-999;
maxtl=0;
for (m=10;m<50;m++){
tl=0.01*m;
tr=trs(tl,th);
w1=wel(tl,tr,th);
if (w1>maxw)maxtl=tl;
if (w1>maxw)maxw=w1;
}
return maxtl;
}
double wel(double tl,double tr,double th[]){
double c1,l1,w1;
int s;
w1=0;
for (s=1;s<101;s++){
l1=lx(s,tl,tr,th);
c1=(1-tl)*th[s]*l1+tr;
w1=w1+u(c1,1-l1);;
}
return w1;
}
double u(double c1,double x1){
double u1,c2,x2;
int pp;
pp=0;
c2=c1;
x2=x1;
if (c2<0)pp=100;
if (x2<0)pp=100;
if (x2>1)pp=100;
if (x2==0)pp=100;
if (pp>50)c2=0.5;
if (pp>50)x2=0.5;
u1=Math.log(c2)+Math.log(x2);
if (pp>50)u1=-999;
return u1;
}
}
最終更新:2013年09月24日 01:16