import java.awt.*;
class dsge extends Frame {
public static void main(String[] args) {
new dsge();
}
dsge() {
super("JAVA DSGE 33 労働供給非弾力的");
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=grape();
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[] grape(){
double a;
double beta;
double ks;
double h;
double k[]=new double[101];
double cx[]=new double[101];
double cp[]=new double[101];
double cons[]=new double[101];
double k1;
double n1;
int n2;
int n3;
int n;
double c1;
double r1;
double ep;
int t;
int x1;
int x2;
int time;
double minc;
double maxc;
a=0.33;
beta=0.95;
ks=Math.pow((1 / beta - 1) / a , 1 / (a - 1));
h=2*ks/100;
for (n=1;n<101;n++){
k[n]=n*h;
cx[n]=Math.pow(k[n],a);
}
t=0;
while(t<100){
for (n=10;n<91;n++){
k1=k[n]+Math.pow(k[n],a)-cx[n];
n1=k1/h;
n2=(int)n1;
n3=n2+1;
c1=cx[n2]+(n1-n2)*(cx[n3]-cx[n2]);
r1=a*Math.pow(k1,a-1);
cp[n]=c1/(beta*(1+r1));
}
ep=0;
for (n=10;n<91;n++){
ep=ep+Math.pow(cx[n]-cp[n],2);
}
for (n=10;n<91;n++){
cx[n]=cp[n];
}
if (ep<0.0001){
t=1000;
}
t=t+1;
}
k1=k[45];
for (time=1;time<101;time++){
n1=k1/h;
n2=(int)n1;
n3=n2+1;
cons[time]=cx[n2]+(n1-n2)*(cx[n3]-cx[n2]);
k1=k1+Math.pow(k1,a)-cons[time];
}
minc=999;
for (time=1;time<101;time++){
if(cons[time]<minc)minc=cons[time];
}
maxc=-999;
for (time=1;time<101;time++){
if(cons[time]>maxc)maxc=cons[time];
}
for (time=1;time<101;time++){
cons[time]=(cons[time]-minc)/(maxc-minc);
}
return cons;
}
}
最終更新:2009年12月21日 16:01