アットウィキロゴ

JAVA DSGE 29

import javax.swing.*;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.*;
import java.awt.Color;
import java.awt.BasicStroke;

public class dsge29 extends JPanel{

  public static void main(String[] args){
    JFrame frame = new JFrame();
    dsge29 app = new dsge29();
    frame.getContentPane().add(app);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setBounds(0, 0, 500, 500);
    frame.setTitle("dsge29");
    frame.setVisible(true);
  }

public void paintComponent(Graphics g){
int n;    
double data[]=new double[101];
Graphics2D g2 = (Graphics2D)g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                        RenderingHints.VALUE_ANTIALIAS_ON);
data=dsge();
for (n=1;n<95;n++){
g2.draw(new Line2D.Double(4*n, 500-400*data[n], 4*n+4,500-400*data[n+1]));
}  
}
static double[] dsge(){
double a;
double beta;
double ks;
double h;
double k[]=new double[101];
double cx[]=new double[101];
double cp[]=new double[101];
double k1;
double n1;
int n2;
int n3;
int n;
double c1;
double r1;
double ep;
double maxc;
double minc;
double data[]=new double[101];
double ct[]=new double[101];
int t;
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[47];
for (t=1;t<101;t++){
n1=k1/h;
n2=(int)n1;
n3=n2+1;
c1=cx[n2]+(n1-n2)*(cx[n3]-cx[n2]);
k1=k1+Math.pow(k1,a)-c1;
ct[t]=c1;
}
minc=999;
for (t=1;t<100;t++){
if (ct[t]<minc)minc=ct[t];
}
maxc=-999;
for (t=1;t<100;t++){
if (ct[t]>maxc)maxc=ct[t];
}
for (t=1;t<100;t++){
data[t]=(ct[t]-minc)/(maxc-minc);
}
return data;
}
}
最終更新:2010年01月04日 10:42