class pro{
public static void main(String args[]){
int s,m,n,j;
double th[]= new double[11];
double y[]= new double[11];
double c[]= new double[11];
double a[][]=new double[51][91];
int p1;
int p2[]=new int[41];
int p3[]=new int[41];
double tl,tr,w1;
double h;
double y1,y2,uc,uy,u1,u2;
double maxv,minv;
int maxn,maxm;
int px,t1;
double x1,x2,z;
for (s=1;s<11;s++){
th[s]=1+0.1*s;
}
tl=tls(th);
tr=trs(tl,th);
for(s=1;s<11;s++){
y[s]=th[s]*lx(s,tl,tr,th);
c[s]=(1-tl)*y[s]+tr;
}
System.out.println(tl);
System.out.println(tr);
h=0.05;
for (m=0;m<41;m++){
for (n=0;n<91;n++){
a[m][n]=0;
}
}
for (m=1;m<41;m++){
a[m][m]=1;
}
for (m=1;m<51;m++){
a[m][m+40]=1;
}
for (m=1;m<41;m++){
a[m][0]=h;
}
for (s=1;s<11;s++){
n=4*(s-1)+1;
a[50][n]=1;
a[50][n+1]=-1;
a[50][n+2]=-1;
a[50][n+3]=1;
}
for (s=1;s<11;s++){
n=4*s-3;
uc=Math.log(c[s]+h)-Math.log(c[s]);
a[0][n]=uc/h;
uc=Math.log(c[s]-h)-Math.log(c[s]);
a[0][n+1]=uc/h;
y1=y[s]+h;
y2=y[s];
uy=Math.log(1-y1/th[s])-Math.log(1-y2/th[s]);
a[0][n+2]=uy/h;
y1=y[s]-h;
y2=y[s];
uy=Math.log(1-y1/th[s])-Math.log(1-y2/th[s]);
a[0][n+3]=uy/h;
}
for (s=2;s<11;s++){
m=39+s;
u1=Math.log(c[s])+Math.log(1-y[s]/th[s]);
u2=Math.log(c[s-1])+Math.log(1-y[s-1]/th[s]);
a[m][0]=u1-u2;
}
for (s=2;s<11;s++){
m=39+s;
n=4*(s-1)+1;
uc=Math.log(c[s]+h)-Math.log(c[s]);
a[m][n]=-uc/h;
n=4*(s-1)+2;
uc=Math.log(c[s]-h)-Math.log(c[s]);
a[m][n]=-uc/h;
n=4*(s-1)+3;
y1=y[s]+h;
y2=y[s];
uy=Math.log(1-y1/th[s])-Math.log(1-y2/th[s]);
a[m][n]=-uy/h;
n=4*(s-1)+4;
y1=y[s]-h;
y2=y[s];
uy=Math.log(1-y1/th[s])-Math.log(1-y2/th[s]);
a[m][n]=-uy/h;
n=4*(s-2)+1;
uc=Math.log(c[s-1]+h)-Math.log(c[s-1]);
a[m][n]=uc/h;
n=4*(s-2)+2;
uc=Math.log(c[s-1]-h)-Math.log(c[s-1]);
a[m][n]=uc/h;
n=4*(s-2)+3;
y1=y[s-1]+h;
y2=y[s-1];
uy=Math.log(1-y1/th[s])-Math.log(1-y2/th[s]);
a[m][n]=uy/h;
n=4*(s-2)+4;
y1=y[s-1]-h;
y2=y[s-1];
uy=Math.log(1-y1/th[s])-Math.log(1-y2/th[s]);
a[m][n]=uy/h;
}
maxv=0;
maxn=9999;
for (n=1;n<91;n++){
if (a[0][n]>maxv)maxn=n;
if (a[0][n]>maxv)maxv=a[0][n];
}
System.out.println(maxn);
t1=0;
while(t1<1000){
minv=999;
maxm=9999;
for (m=1;m<51;m++){
x1=a[m][maxn];
px=0;
if (x1==0)px=100;
if (x1<0)px=100;
if (px>50)x1=1;
x2=a[m][0]/x1;
if (px>50)x2=1000;
if (x2<0)x2=1000;
if (x2<minv)maxm=m;
if (x2<minv)minv=x2;
}
System.out.println(maxm);
for (m=0;m<51;m++){
z=a[m][maxn]/a[maxm][maxn];
if (maxm==m)z=0;
for (n=0;n<91;n++){
a[m][n]=a[m][n]-z*a[maxm][n];
}
}
maxv=0;
maxn=9999;
for (n=1;n<91;n++){
if (a[0][n]>maxv)maxn=n;
if (a[0][n]>maxv)maxv=a[0][n];
}
System.out.println(maxn);
if (maxn>9000)t1=10000;
t1=t1+1;
}
for (n=1;n<41;n++){
p1=0;
p3[n]=0;
for (m=1;m<51;m++){
if (a[m][n]==0)p1=p1+1;
if (a[m][n]>0)p3[n]=m;
if (a[m][n]<0)p3[n]=m;
}
p2[n]=0;
if (p1==49)p2[n]=100;
}
for (n=1;n<41;n++){
m=p3[n];
if (p2[n]>50)System.out.println(n) ;
if (p2[n]>50)System.out.println(a[m][0]/a[m][n]) ;
}
}
static 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;
}
static double bud(double tl,double tr,double th[]){
double c1,y1,b1;
int s;
b1=0;
for (s=1;s<11;s++){
y1=th[s]*lx(s,tl,tr,th);
c1=(1-tl)*y1+tr;
b1=b1+y1-c1;
}
return b1;
}
static 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;
}
static double tls(double th[]){
int m;
double tl,tr,w1,maxw,maxtl;
maxw=-999;
maxtl=0;
for (m=10;m<200;m++){
tl=0.001*m;
tr=trs(tl,th);
w1=wel(tl,tr,th);
if (w1>maxw)maxtl=tl;
if (w1>maxw)maxw=w1;
}
return maxtl;
}
static double wel(double tl,double tr,double th[]){
double c1,l1,w1;
int s;
w1=0;
for (s=1;s<11;s++){
l1=lx(s,tl,tr,th);
c1=(1-tl)*th[s]*l1+tr;
w1=w1+u(c1,1-l1);;
}
return w1;
}
static 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;
}
}
最終更新:2010年06月26日 11:44