アットウィキロゴ

dsげ0610

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package dsge;

import java.awt.*;
import java.awt.event.*;

class pro extends Frame implements Runnable{

double a;
double beta;
double ks;
double h;
double k[]=new double[101];
double cx[]=new double[101];
double cxs[]=new double[101];
double lx[]=new double[101];
double lxs[]=new double[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;

double ct[]=new double[101];


public static void main(String [] args) {
       Frame f=new pro();
       f.setTitle("dsge0107");
       f.setSize(700,700);
       f.setBackground(Color.yellow);
       f.setVisible(true);
   }

pro(){

a=0.33;
beta=0.95;
ls=(1-a)/(2-a);
ks=ls*Math.pow((1 / beta - 1) / a , 1 / (a - 1)) ;
h=2*(double)ks/100;
for (n=1;n<101;n++){
k[n]=n*h;
lx[n]=ls;
cx[n]=Math.pow(k[n],a)*Math.pow(ls,1-a);
}
t=0;
while(t<100){
for (n=10;n<91;n++){
k1=k[n]+Math.pow(k[n],a)*Math.pow(lx[n],1-a)-cx[n];
n1=(double)k1/h;
n2=(int)n1;
n3=n2+1;
c1=cx[n2]+(n1-n2)*(cx[n3]-cx[n2]);
l1=lx[n2]+(n1-n2)*(lx[n3]-lx[n2]);
r1=a*Math.pow(k1,a-1)*Math.pow(l1,1-a);
cxs[n]=(double)c1/(beta*(1+r1));
w1=(1-a)*Math.pow(k1,a)*Math.pow(l1,-a);
lxs[n]=1-cx[n]/w1;
}
ep=0;
for (n=10;n<91;n++){
ep=ep+Math.pow(cx[n]-cxs[n],2)+Math.pow(lx[n]-lxs[n],2);
}
for (n=10;n<91;n++){
cx[n]=cxs[n];
lx[n]=lxs[n];
}
if (ep<0.0001){
t=1000;
}
t=t+1;
}


k1=k[40];
for(t=1;t<100;t++){
n1=(double)k1/h;
n2=(int)n1;
n3=n2+1;
c1=cx[n2]+(n1-n2)*(cx[n3]-cx[n2]);
ct[t]=lx[n2]+(n1-n2)*(lx[n3]-lx[n2]);
k1=k1+Math.pow(k1,a)*Math.pow(ct[t],1-a)-c1;
}






Thread th=new Thread(this);
th.start();
addWindowListener(new stopwin());
}


class stopwin extends WindowAdapter{
   public void windowClosing(WindowEvent we){System.exit(0);}
}


public void run(){
t=1;
while(t<100){
repaint();
try{
Thread.sleep(100);
}catch(InterruptedException e){}
t=t+1;
}
repaint();
}

public void paint(Graphics g){
int p1;
p1=(int)(100*ct[t]);
g.fillRect(100+5*t,600-p1,10,10);
g.drawLine(100,600,100,100);
g.drawLine(100,600,600,600);


}

}
最終更新:2011年06月09日 23:38