class pro{
double[][] x=new double[3][3];
double[] y=new double[3];
double[] a=new double[3];
double[] d=new double[3];
double[] vec=new double[3];
double b,e,delta;
int s,point,m,n;
public static void main(String args[]){
pro test=new pro();
}
pro(){
delta=0.01;
x[1][1]=2;
x[1][2]=1;
x[2][1]=1;
x[2][2]=2;
y[1]=1;
y[2]=-1;
a[1]=3;
a[2]=-2;
b=5;
s=0;
while(s<1000){
point=makepoint();
for(n=1;n<3;n++){
d[n]=df(point,n);
}
e=d[1]*d[1]+d[2]*d[2];
e=Math.pow(e,0.5);
for(n=1;n<3;n++){
vec[n]=d[n]/e;
}
for(n=1;n<3;n++){
a[n]=a[n]+delta*vec[n];
}
System.out.println(met(a,b,point,x));
s=s+1;
}
}
int makepoint(){
int m,h,ps;
double p1,minp;
ps=0;
minp=999;
for(m=1;m<3;m++){
p1=9999;
h=0;
if(g(a,b,m,x)>0)h=h+1;
if(y[m]>0)h=h+1;
if(h==2)p1=met(a,b,m,x);
h=0;
if(g(a,b,m,x)<0)h=h+1;
if(y[m]<0)h=h+1;
if(h==2)p1=met(a,b,m,x);
if(p1<minp)ps=m;
if(p1<minp)minp=p1;
}
return ps;
}
double df(int m,int n){
double delta,m1,m2;
double[] alpha=new double[3];
delta=0.01;
alpha[1]=a[1];
alpha[2]=a[2];
alpha[n]=alpha[n]+delta;
m1=met(a,b,m,x);
m2=met(alpha,b,m,x);
return (m2-m1)/delta;
}
double met(double[] a,double b,int m,double[][] x){
double m1,m2,t,mt;
m1=a[1]*a[1]+a[2]*a[2];
m2=-b-a[1]*x[m][1]-a[2]*x[m][2];
t=m2/m1;
mt=t*t*m1;
mt=Math.pow(mt,0.5);
return mt;
}
double g(double[] a,double b,int m,double[][] x){
double g1;
g1=a[1]*x[m][1]+a[2]*x[m][2]+b;
return g1;
}
}
最終更新:2011年06月02日 23:55