アットウィキロゴ

78965

package dsge3;
 
import java.io.*;
 
public class pro {
 
    String str;
    String[] data=new String[500];
    double[] point=new double[101];
    int[] p=new int[101];
    int s,datanumber;
 
    public static void main(String[] args) {
       pro test=new pro();
    }
pro(){
 
 
    dsge sub2=new dsge();
    point=sub2.point;
 
    double maxp,minp;
 
    maxp=0;
    for(s=1;s<101;s++){
    if(point[s]>maxp)maxp=point[s];
    }
 
    minp=999;
    for(s=1;s<101;s++){
    if(point[s]<minp)minp=point[s];
    }
 
    for(s=1;s<101;s++){
    p[s]=(int)(500*(point[s]-minp)/(maxp-minp));
    }
 
    svg sub=new svg();
 
 
   for(s=1;s<100;s++){
    data[s]=sub.line(100+5*s,600-p[s],105+5*s,600-p[s+1],"RED",2);
   }
    datanumber=101;
     data[100]=sub.line(100,100,100,600,"BLACK",2);
      data[101]=sub.line(100,600,600,600,"BLACK",2);
 
      writefile("dsge.svg");
 
 
}
 
void writefile(String file){ 
 
try{ 
PrintWriter pw = new PrintWriter (new BufferedWriter(new FileWriter(file))); 
 
pw.println("<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">");
for(s=1;s<datanumber+1;s++){
pw.println(data[s]);
}
pw.println("</svg>");
 
 
System.out.println("ABC"); 
pw.close(); 
} catch(IOException ep){ System.out.println("ABC"); } 
 
 
} 
 
}
 
 
package dsge3;
 
 
public class dsge{
 
double[] cn=new double[101];
double[] ln=new double[101];
double[] cm=new double[101];
double[] lm=new double[101];
 
double[] chcn=new double[101];
double[] chln=new double[101];
double[] chcm=new double[101];
double[] chlm=new double[101];
 
 
 
double[] k=new double[101];
double[] point=new double[101];
double[] th=new double[101];
 
double a,beta,ep;
 
    double ks,h,ls;
    int n,mode,time,m;
 
 
 
dsge(){
 
a=0.33;
beta=0.95;
 
for(m=1;m<101;m++){
th[m]=0.95+0.001*m;
lm[m]=0;
cm[m]=0;
}
 
ls=(1-a)/(2-a);
ks=ls*Math.pow((1 / beta - 1) / a , 1 / (a - 1)); 
h=2*ks/100; 
 
m=50;
for (n=1;n<101;n++){ 
k[n]=n*h; 
ln[n]=ls;
cn[n]=th[m]*f(k[n],ln[n]); 
} 
 
 
int card;
card=0; 
 
while(card<100){
 
mode=0;
 
while(mode<100){
 
simple();
 
if(ep<0.0001)mode=1000;
 
mode=mode+1;
 
 
}
mode=0;
 
while(mode<100){
 
sec();
 
if(ep<0.0001)mode=1000;
 
mode=mode+1;
 
 
}
 
check();
 
if(ep<0.001)card=1000;
card=card+1;
 
}
 
double k1,l1,n1;
int t;
 
 
k1=k[50];
for(t=1;t<101;t++){
n1=k1/h;
m=(int)(100*Math.random())+1;
k1=k1+th[m]*f(k1,lab(m,n1))-con(m,n1);
point[t]=con(m,n1);
}
 
}
 
void check(){
 
 
ep=0; 
for (n=10;n<91;n++){ 
ep=ep+Math.pow(cn[n]-chcn[n],2)+Math.pow(ln[n]-chln[n],2); 
} 
 
for (m=1;m<101;m++){ 
ep=ep+Math.pow(cm[m]-chcm[m],2)+Math.pow(lm[m]-chlm[m],2); 
} 
 
for (m=1;m<101;m++){ 
chcm[m]=cm[m]; 
chlm[m]=lm[m];
}  
 
 
 
for (n=10;n<91;n++){ 
chcn[n]=cn[n]; 
chln[n]=ln[n];
}  
 
 
 
 
 
 
 
 
 
}
 
void simple(){ 
 
double k1,l1,n1,c1,r1,uc,w1; 
int mx; 
 
 
double cns[]=new double[101]; 
double lns[]=new double[101]; 
 
m=50; 
 
for (n=10;n<91;n++){ 
 
k1=k[n]+th[m]*f(k[n],lab(m,n))-con(m,n); 
n1=(double)k1/h; 
 
uc=0;
for (mx=1;mx<101;mx++){ 
c1=con(mx,n1); 
l1=lab(mx,n1);
r1=a*th[mx]*Math.pow(k1,a-1)*Math.pow(l1,1-a); 
uc=uc+(beta*(1+r1))/c1;  
}
uc=0.01*uc;
cns[n]=1/uc-cm[m];
w1=th[m]*(1-a)*Math.pow(k[n],a)*Math.pow(lab(m,n),-a); 
 
 
lns[n]=1-con(m,n)/w1-lm[m];
} 
 
ep=0; 
for (n=10;n<91;n++){ 
ep=ep+Math.pow(cn[n]-cns[n],2)+Math.pow(ln[n]-lns[n],2); 
} 
 
for (n=10;n<91;n++){ 
cn[n]=cns[n]; 
ln[n]=lns[n];
}  
 
 
} 
 
void sec(){ 
 
double k1,l1,n1,c1,r1,uc,w1; 
int mx; 
 
 
double cms[]=new double[101]; 
double lms[]=new double[101]; 
n=50; 
 
 
for (m=1;m<101;m++){ 
k1=k[n]+th[m]*f(k[n],lab(m,n))-con(m,n); 
n1=(double)k1/h; 
uc=0;
for (mx=1;mx<101;mx++){ 
c1=con(mx,n1); 
l1=lab(mx,n1);
r1=a*th[mx]*Math.pow(k1,a-1)*Math.pow(l1,1-a); 
uc=uc+(beta*(1+r1))/c1;  
}
uc=0.01*uc;
cms[m]=1/uc-cn[n];
w1=th[m]*(1-a)*Math.pow(k[n],a)*Math.pow(lab(m,n),-a); 
lms[m]=1-con(m,n)/w1-ln[n];
} 
 
ep=0; 
for (m=1;m<101;m++){ 
ep=ep+Math.pow(cm[m]-cms[m],2)+Math.pow(lm[m]-lms[m],2); 
} 
 
for (m=1;m<101;m++){ 
cm[m]=cms[m]; 
lm[m]=lms[m];
}  
 
 
} 
 
double f(double k1,double l1){
double c1;
c1=Math.pow(k1,a)*Math.pow(l1,1-a);    
return c1;    
}
 
 
double lab(int m,double n1){
int n2,n3;
double c1;
n2=(int)n1; 
n3=n2+1;      
c1=ln[n2]+(n1-n2)*(ln[n3]-ln[n2])+lm[m];     
return c1;    
}
double con(int m,double n1){
int n2,n3;
double c1;
n2=(int)n1; 
n3=n2+1;      
c1=cn[n2]+(n1-n2)*(cn[n3]-cn[n2])+cm[m];     
return c1;    
}
 
}
 
 
 
package dsge3;
 
public class svg{
 
String text(int x,int y,String strx,String col){
String str;
str="<text x=\""+x+"\" y=\""+y+"\" fill=\""+col+"\">"+strx+"</text>";
return str;
}
 
String line(int x1,int y1,int x2,int y2,String col,int w){
String str;
str="<line x1=\""+x1+"\" y1=\""+y1+"\" x2=\""+x2+"\" y2=\""+y2+"\" style=\"stroke:"+col+";stroke-width:"+w+"\"/>";
 
return str;
}
 
String circle(int x,int y,int r,String col){
String str;
str="<circle cx=\""+x+"\" cy=\""+y+"\" r=\""+r+"\" fill=\""+col+"\"/>";
 
return str;
}
 
 
 
String rect(int x1,int y1,int w1,int h1,String col){
String str;
str="<rect x=\""+x1+"\" y=\""+y1+"\"width=\""+w1+"\" height=\""+h1+"\" fill=\""+col+"\"/>";
 
return str;
}
 
}
 
最終更新:2013年09月23日 05:13