import java.awt.*;
import javax.swing.*;
public class dsge36 extends JFrame {
public static void main(String args[]) {
new dsge36();
}
public dsge36() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
getContentPane().add(new pp());
setSize(500,500);
setTitle("dsge36");
setVisible(true);
}
}
class pp extends JPanel {
public pp(){setBackground(Color.white);}
public void paintComponent(Graphics g) {
double data[]= new double[101];
int n;
int y1,y2;
super.paintComponent(g);
g.drawString("練習", 100,400);
g.setColor(Color.red);
data=dsge();
for (n=1;n<100;n++){
y1=(int)(500-500*data[n]);
y2=(int)(500-500*data[n+1]);
g.drawLine(5*n,y1,5*n+5,y2);
}
}
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 lx[]=new double[101];
double lp[]=new double[101];
double data[]=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;
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;
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=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);
cp[n]=c1/(beta*(1+r1));
w1=(1-a)*Math.pow(k1,a)*Math.pow(l1,-a);
lp[n]=1-cx[n]/w1;
}
ep=0;
for (n=10;n<91;n++){
ep=ep+Math.pow(cx[n]-cp[n],2)+Math.pow(lx[n]-lp[n],2);
}
for (n=10;n<91;n++){
cx[n]=cp[n];
lx[n]=lp[n];
}
if (ep<0.0001){
t=1000;
}
t=t+1;
}
k1=k[40];
for (t=1;t<101;t++){
n1=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]);
k1=k1+Math.pow(k1,a)*Math.pow(l1,1-a)-c1;
data[t]=l1;
}
return data;
}
}
最終更新:2010年01月05日 20:11