import java.awt.*;
import java.awt.event.*;
class pro extends Frame{
int s1,s2;
double th1[]=new double[6];
double th2[]=new double[6];
double c[][]=new double[6][6];
double y1[][]=new double[6][6];
double y2[][]=new double[6][6];
double cp[][][]=new double[6][6][3];
double yp1[][][]=new double[6][6][3];
double yp2[][][]=new double[6][6][3];
double u[][][]=new double[6][6][3];
double w[][][]=new double[6][6][3];
double z[][][]=new double[6][6][3];
int op[][]=new int[6][6];
double h,maxv;
double cs,ys1,ys2;
int n,e,e1,e2,e3;
public static void main(String args[]){
pro f = new pro();
f.setSize(700,700);
f.setTitle("夫婦の最適所得税");
f.setBackground(Color.blue) ;
f.setVisible(true);
}
pro(){
addWindowListener(new stopwin());
for (s1=1;s1<6;s1++){
th1[s1]=0.2*s1;
}
for (s2=1;s2<6;s2++){
th2[s2]=0.1*s2;
}
linear ln=new linear();;
ln.th1=th1;
ln.th2=th2;
ln.makedata();
c=ln.c;
y1=ln.y1;
y2=ln.y2;
h=0.001;
while(h>0.0005){
for (s1=1;s1<6;s1++){
for (s2=1;s2<6;s2++){
for (n=-1;n<2;n++){
cs=c[s1][s2]-n*h;
ys1=y1[s1][s2];
ys2=y2[s1][s2];
u[s1][s2][n+1]=ux(cs,1-ys1/th1[s1],1-ys2/th2[s2]);
}
}
}
for (s1=1;s1<5;s1++){
for (s2=1;s2<6;s2++){
for (n=-1;n<2;n++){
cs=c[s1][s2]-n*h;
ys1=y1[s1][s2];
ys2=y2[s1][s2];
w[s1][s2][n+1]=ux(cs,1-ys1/th1[s1+1],1-ys2/th2[s2]);
}
}
}
for (s1=1;s1<6;s1++){
for (s2=1;s2<5;s2++){
for (n=-1;n<2;n++){
cs=c[s1][s2]-n*h;
ys1=y1[s1][s2];
ys2=y2[s1][s2];
z[s1][s2][n+1]=ux(cs,1-ys1/th1[s1],1-ys2/th2[s2+1]);
}
}
}
for (s1=1;s1<6;s1++){
for (s2=1;s2<5;s2++){
for (n=-1;n<2;n++){
cp[s1][s2][n+1]=c[s1][s2]-n*h;
yp1[s1][s2][n+1]=y1[s1][s2];
yp2[s1][s2][n+1]=y2[s1][s2];
}
}
}
non nl=new non();
nl.th1=th1;
nl.th2=th2;
nl.z=z;
nl.u=u;
nl.w=w;
nl.cp=cp;
nl.yp1=yp1;
nl.yp2=yp2;
nl.makedata();
maxv=nl.maxv;
op=nl.op;
e1=nl.e;
for (s1=1;s1<6;s1++){
for (s2=1;s2<6;s2++){
n=op[s1][s2];
c[s1][s2]=c[s1][s2]-h*n;
}
}
for (s1=1;s1<6;s1++){
for (s2=1;s2<6;s2++){
for (n=-1;n<2;n++){
cs=c[s1][s2];
ys1=y1[s1][s2]+n*h;
ys2=y2[s1][s2];
u[s1][s2][n+1]=ux(cs,1-ys1/th1[s1],1-ys2/th2[s2]);
}
}
}
for (s1=1;s1<5;s1++){
for (s2=1;s2<6;s2++){
for (n=-1;n<2;n++){
cs=c[s1][s2];
ys1=y1[s1][s2]+n*h;
ys2=y2[s1][s2];
w[s1][s2][n+1]=ux(cs,1-ys1/th1[s1+1],1-ys2/th2[s2]);
}
}
}
for (s1=1;s1<6;s1++){
for (s2=1;s2<5;s2++){
for (n=-1;n<2;n++){
cs=c[s1][s2];
ys1=y1[s1][s2]+n*h;
ys2=y2[s1][s2];
z[s1][s2][n+1]=ux(cs,1-ys1/th1[s1],1-ys2/th2[s2+1]);
}
}
}
for (s1=1;s1<6;s1++){
for (s2=1;s2<5;s2++){
for (n=-1;n<2;n++){
cp[s1][s2][n+1]=c[s1][s2];
yp1[s1][s2][n+1]=y1[s1][s2]+n*h;
yp2[s1][s2][n+1]=y2[s1][s2];
}
}
}
nl.z=z;
nl.u=u;
nl.w=w;
nl.cp=cp;
nl.yp1=yp1;
nl.yp2=yp2;
nl.makedata();
maxv=nl.maxv;
op=nl.op;
e2=nl.e;
for (s1=1;s1<6;s1++){
for (s2=1;s2<6;s2++){
n=op[s1][s2];
y1[s1][s2]=y1[s1][s2]+h*n;
}
}
for (s1=1;s1<6;s1++){
for (s2=1;s2<6;s2++){
for (n=-1;n<2;n++){
cs=c[s1][s2];
ys1=y1[s1][s2];
ys2=y2[s1][s2]+n*h;
u[s1][s2][n+1]=ux(cs,1-ys1/th1[s1],1-ys2/th2[s2]);
}
}
}
for (s1=1;s1<5;s1++){
for (s2=1;s2<6;s2++){
for (n=-1;n<2;n++){
cs=c[s1][s2];
ys1=y1[s1][s2];
ys2=y2[s1][s2]+n*h;
w[s1][s2][n+1]=ux(cs,1-ys1/th1[s1+1],1-ys2/th2[s2]);
}
}
}
for (s1=1;s1<6;s1++){
for (s2=1;s2<5;s2++){
for (n=-1;n<2;n++){
cs=c[s1][s2];
ys1=y1[s1][s2];
ys2=y2[s1][s2]+n*h;
z[s1][s2][n+1]=ux(cs,1-ys1/th1[s1],1-ys2/th2[s2+1]);
}
}
}
for (s1=1;s1<6;s1++){
for (s2=1;s2<5;s2++){
for (n=-1;n<2;n++){
cp[s1][s2][n+1]=c[s1][s2];
yp1[s1][s2][n+1]=y1[s1][s2];
yp2[s1][s2][n+1]=y2[s1][s2]+n*h;
}
}
}
nl.z=z;
nl.u=u;
nl.w=w;
nl.cp=cp;
nl.yp1=yp1;
nl.yp2=yp2;
nl.makedata();
maxv=nl.maxv;
op=nl.op;
e3=nl.e;
for (s1=1;s1<6;s1++){
for (s2=1;s2<6;s2++){
n=op[s1][s2];
y2[s1][s2]=y2[s1][s2]+h*n;
}
}
e=e1+e2+e3;
System.out.println(e);
System.out.println(maxv);
if(e<1)h=h/2;
}
}
double ux(double c1,double x1,double x2){
double c2,x3,x4,u1;
int px;
c2=c1;
x3=x1;
x4=x2;
px=0;
if (c2<0)px=100;
if (c2==0)px=100;
if (x3<0)px=100;
if (x3==0)px=100;
if (x3>1)px=100;
if (x4<0)px=100;
if (x4==0)px=100;
if (x4>1)px=100;
if (px>50)c2=0.5;
if (px>50)x3=0.5;
if (px>50)x4=0.5;
u1=Math.log(c2)+Math.log(x3)+Math.log(x4);
if (px>50)u1=-999;
return u1;
}
class stopwin extends WindowAdapter{
public void windowClosing(WindowEvent we){System.exit(0);}
}
public void paint(Graphics g){
int x1,z1,x2,z2;
g.drawLine(100,600,600,600);
g.drawLine(100,600,100,100);
s2=1;
for(s1=1;s1<5;s1++){
z1=(int)(600-500*y1[s1][s2]);
x1=(int)(100+500*th1[s1]);
z2=(int)(600-500*y1[s1+1][s2]);
x2=(int)(100+500*th1[s1+1]);
g.drawLine(x1,z1,x2,z2);
}
g.setColor(Color.red);
s2=5;
for(s1=1;s1<5;s1++){
z1=(int)(600-500*y1[s1][s2]);
x1=(int)(100+500*th1[s1]);
z2=(int)(600-500*y1[s1+1][s2]);
x2=(int)(100+500*th1[s1+1]);
g.drawLine(x1,z1,x2,z2);
}
}
}
最終更新:2011年08月11日 14:48