アットウィキロゴ

グラフ SVG

package graph;
 
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
 
 
public class pro {
 
double maxp,minp;
int supp,infp;
int number;
int[] sline=new int[100];
int[] pline=new int[100];
int s;
String[] data=new String[500];
int datanumber;
double[] point=new double[101];
 
 
double[] cn=new double[101];
double[] ln=new double[101];
double[] cm=new double[101];
double[] lm=new double[101];
double[] pm=new double[101];
double[] pn=new double[101];
 
double[] k=new double[101];
double[] pc=new double[101];
double[] th=new double[101];
 
 
double a,beta,ms;
    double ks,h,ls;
    int n,m;
 
    int[] px=new int[101];
    double[] p=new double[101];
 
 
    public static void main(String[] args) {
        pro test=new pro();
    }
pro(){
a=0.33;
beta=0.95;
ms=20;
 
for(m=1;m<101;m++){
th[m]=0.95+0.001*m;
}
 
simple sub3=new simple();
sub3.a=a;
sub3.beta=beta;
sub3.th=th;
sub3.makedata();
cn=sub3.cn;
cm=sub3.cm;
ln=sub3.ln;
lm=sub3.lm;
k=sub3.k;
h=sub3.h;
 
 
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);
}
 
graph sub=new graph();
sub.point=point;
sub.makedata();
 
 
 
}
double price(int m,double nx){
double c1;
int n1,n2;
n1=(int)nx;
n2=n1+1;
c1=pn[n1]+(nx-n1)*(pn[n2]-pn[n1])+pm[m];
return c1;
}
 
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 graph;
 
 
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
 
 
public class graph {
 
double maxp,minp;
int supp,infp;
int number;
int[] sline=new int[500];
int[] pline=new int[500];
int s;
String[] data=new String[500];
int datanumber;
double[] point=new double[101];
double[] p=new double[101];
int[] pp=new int[101];
double p1,avgp;  
 
void makedata(){
 
p1=0;
for(s=1;s<101;s++){    
p1=p1+point[s];
}    
avgp=p1/100;    
 
 
for(s=1;s<101;s++){    
p[s]=100*(point[s]/avgp-1);
}    
 
maxp=0;
for(s=1;s<101;s++){    
if(p[s]>maxp)maxp=p[s];
}    
 
minp=999;
for(s=1;s<101;s++){    
if(p[s]<minp)minp=p[s];
}    
 
infp=(int)minp-1;
supp=(int)maxp+1;
 
number=supp-infp;
 
for(s=1;s<number;s++){
sline[s]=infp+s;
}
 
for(s=1;s<number;s++){
pline[s]=(500*(sline[s]-infp))/(supp-infp);
}
 
for(s=1;s<101;s++){
pp[s]=(int)(500*(p[s]-infp))/(supp-infp);
}
 
 svg sub=new svg();
 
data[1]=sub.line(100,100,100,600,"BLACK",2);
data[2]=sub.line(100,600,600,600,"BLACK",2);
data[3]=sub.text(100,100,"消費","BLACK");
data[4]=sub.text(600,600,"期間","BLACK");
 
int z1,sx;
 
sx=4;
for(s=1;s<number;s++){
sx=sx+1;
z1=pline[s];
data[sx]=sub.line(100,600-z1,600,600-z1,"BLUE",1);
}  
 
String str1;
 
for(s=1;s<number;s++){
sx=sx+1;
z1=pline[s];
str1=""+sline[s]+"%";
data[sx]=sub.text(80,600-z1,str1,"BLUE");
}  
 
for(s=1;s<100;s++){
sx=sx+1;
data[sx]=sub.line(100+5*s,600-pp[s],105+5*s,600-pp[s+1],"RED",2);
}  
 
datanumber=sx;
 
writefile("dsge.svg");
 
 
 
 
}
void writefile(String file){ 
 
    int s;
 
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 graph;
 
 
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;
}
 
}
 
 
package graph;
 
 
public class simple {
 
double[] cn=new double[101];
double[] ln=new double[101];
double[] cm=new double[101];
double[] lm=new double[101];
double[] pm=new double[101];
double[] pn=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[] data=new double[101];
double[] th=new double[101];
 
double a,beta,ep;
 
    double ks,h,ls;
    int n,mode,time,m;
 
 
void makedata(){
 
for(m=1;m<101;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){
 
 
capital();
 
techno();
 
check();
 
if(ep<0.001)card=1000;
card=card+1;
 
}
 
 
}
 
void techno(){
 
    mode=0;
 
while(mode<100){
 
sec();
 
if(ep<0.0001)mode=1000;
 
mode=mode+1;
 
 
}
 
 
}
void capital(){
int mode;
 
mode=0;
 
while(mode<100){
 
simple();
 
if(ep<0.0001)mode=1000;
 
mode=mode+1;
 
 
}
}
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];
}  
 
 
 
 
 
 
 
 
 
}
 
double price(int m,double nx){
double c1;
int n1,n2;
n1=(int)nx;
n2=n1+1;
c1=pn[n1]+(nx-n1)*(pn[n2]-pn[n1])+pm[m];
return c1;
}
 
 
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;    
}
 
}
 
最終更新:2013年09月24日 23:39