import java.awt.*;
class dsge extends Frame {
public static void main(String[] args) {
new dsge();
}
dsge() {
super("JAVA DSGE 35 労働供給弾力的 不確実性");
setSize(500, 500);
setLayout(new BorderLayout());
MyCanvas mc1 = new MyCanvas();
add(mc1, BorderLayout.CENTER);
show();
}
}
class MyCanvas extends Canvas {
public void paint(Graphics g) {
int b;
int x1;
int x2;
int n;
double data[]=new double[101];
g.drawLine(50, 450, 450,450);
g.drawLine(50, 450, 50,50);
data=pro();
for (n=1;n<100;n++){
x1=(int)(450-400*data[n]);
x2=(int)(450-400*data[n+1]);
g.drawLine(50+4*n, x1, 50+4*(n+1),x2);
}
}
static double[] pro(){
double a;
double beta;
double ks;
double h;
double th[]=new double[11];
double k[]=new double[101];
double cx[][]=new double[11][101];
double cp[][]=new double[11][101];
double lx[][]=new double[11][101];
double lp[][]=new double[11][101];
double k1;
double n1;
int n2;
int n3;
int n;
double c1;
double r1;
double ep;
double ls;
double l1;
double w1;
int t;
int m;
int mx;
double uc;
double data[]=new double[101];
double maxdata;
double mindata;
for (m=1;m<11;m++){
th[m]=0.95+0.01*m;
}
a=0.33;
beta=0.95;
ls=(1-a)/(2-a);
ks=ls*Math.pow((1 / beta - 1) / a , 1 / (a - 1));
h=2*ks/100;
for (n=1;n<101;n++){
k[n]=n*h;
for (m=1;m<11;m++){
lx[m][n]=ls;
cx[m][n]=th[m]*Math.pow(k[n],a)*Math.pow(lx[m][n],1-a);
}
}
t=0;
while(t<100){
for (m=1;m<11;m++){
for (n=10;n<91;n++){
k1=k[n]+th[m]*Math.pow(k[n],a)*Math.pow(lx[m][n],1-a)-cx[m][n];
n1=k1/h;
n2=(int)n1;
n3=n2+1;
uc=0;
for (mx=1;mx<11;mx++){
c1=cx[mx][n2]+(n1-n2)*(cx[mx][n3]-cx[mx][n2]);
l1=lx[mx][n2]+(n1-n2)*(lx[mx][n3]-lx[mx][n2]);
r1=th[mx]*a*Math.pow(k1,a-1)*Math.pow(l1,1-a);
uc=uc+(beta*(1+r1))/c1;
}
uc=0.1*uc;
cp[m][n]=1/uc;
w1=th[m]*(1-a)*Math.pow(k[n],a)*Math.pow(lx[m][n],-a);
lp[m][n]=1-cx[m][n]/w1;
}
}
ep=0;
for (m=1;m<11;m++){
for (n=10;n<91;n++){
ep=ep+Math.pow(cx[m][n]-cp[m][n],2)+Math.pow(lx[m][n]-lp[m][n],2);
}
}
for (m=1;m<11;m++){
for (n=10;n<91;n++){
cx[m][n]=cp[m][n];
lx[m][n]=lp[m][n];
}
}
if (ep<0.0001){
t=1000;
}
t=t+1;
}
k1=k[45];
for (t=1;t<101;t++){
m = (int)(Math.random()*10)+1;
n1=k1/h;
n2=(int)n1;
n3=n2+1;
c1=cx[m][n2]+(n1-n2)*(cx[m][n3]-cx[m][n2]);
l1=lx[m][n2]+(n1-n2)*(lx[m][n3]-lx[m][n2]);
k1=k1+th[m]*Math.pow(k1,a)*Math.pow(l1,1-a)-c1;
data[t]=l1;
}
maxdata=-999;
mindata=999;
for (t=1;t<101;t++){
if (data[t]<mindata)mindata=data[t];
}
for (t=1;t<101;t++){
if (data[t]>maxdata)maxdata=data[t];
}
for (t=1;t<101;t++){
data[t]=(data[t]-mindata)/(maxdata-mindata);
}
return data;
}
}
最終更新:2009年12月21日 19:24