アットウィキロゴ

ぷj

import java.io.*;

class dsge{
public static void main(String args[]){
double a,beta;
double ks,h;
double k[]=new double[101];
double cx[]=new double[101];
double cxs[]=new double[101];
double c[]=new double[101];  
double k1,r1,c1;
int n,n2,n3;
double n1;
double e;
int t;
beta=0.95;
a=0.33;
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];
r1=a*Math.pow(k1,a-1);
n1=k1/h;
n2=(int)n1;
n3=n2+1;
c1=cx[n2]+(n1-n2)*(cx[n3]-cx[n2]);
cxs[n]=c1/(beta*(1+r1));
}

e=0;
for (n=10;n<91;n++){
e=e+(cxs[n]-cx[n])*(cxs[n]-cx[n]);
}

for (n=10;n<91;n++){
cx[n]=cxs[n];
}
if (e<0.0001)t=1000;  
t=t+1;
}


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



for (t=1;t<100;t++){
System.out.println(c[t]);
}


try{
PrintWriter pw = new PrintWriter
(new BufferedWriter(new FileWriter("data.txt")));

for (t=1;t<100;t++){  
pw.print(t);
pw.print(",");  
pw.println(c[t]);    
}
System.out.println("ファイルに書きこみました。");

pw.close();
}
catch(IOException ep){
System.out.println("入出力エラーです。");
}





}
}
最終更新:2011年01月06日 22:27