アットウィキロゴ

XCVf54

<html>
<head>
<title>Simple DSGE</title>
<script type="text/javascript">
 
function sample() {
 
var a,beta,ks,h;
var s,mode;
var k1,n1,n2,n3,c1,r1;
var ep;
var maxc,minc;
 
k = new Array(101);
cx = new Array(101);
cxs = new Array(101);
cps = new Array(101);
cp = new Array(101);
 
a=0.33;
beta=0.95;
ks=Math.pow((1/ beta - 1)/a ,1/(a - 1)); 
h=2*ks/100;
 
 
for(s=1;s<101;s++){
k[s]=s*h;
}
 
for(s=1;s<101;s++){
cx[s]=Math.pow(k[s],a);
}
 
 
mode=0;
 
while(mode<10){
 
for(s=10;s<91;s++){
k1=k[s]+Math.pow(k[s],a)-cx[s];
n1=k1/h;
n2=Math.floor(n1);
n3=n2+1;
c1=cx[n2]+(n1-n2)*(cx[n3]-cx[n2]);
r1=a*Math.pow(k1,a-1);
cxs[s]=c1/(beta*(1+r1));
}
 
 
ep=0;
for(s=10;s<91;s++){
ep=ep+(cx[s]-cxs[s])*(cx[s]-cxs[s]);
}
 
 
for(s=10;s<91;s++){
cx[s]=cxs[s];
}
 
if(ep<0.001)mode=1000;
 
mode=mode+1;
 
}
 
 
k1=k[40];
for(s=1;s<101;s++){
n1=k1/h;
n2=Math.floor(n1);
n3=n2+1;
cp[s]=cx[n2]+(n1-n2)*(cx[n3]-cx[n2]);
k1=k1+Math.pow(k1,a)-cp[s];
}
 
 
maxc=0;
for(s=1;s<101;s++){
if(cp[s]>maxc)maxc=cp[s];
}
 
minc=9999;
for(s=1;s<101;s++){
if(cp[s]<minc)minc=cp[s];
}
 
 
 
for(s=1;s<101;s++){
cps[s]=500*(cp[s]-minc)/(maxc-minc);
}
 
var canvas = document.getElementById('camp');
 
var ctx = canvas.getContext('2d');
 
ctx.beginPath();
ctx.fillRect(100,100,3,500);
ctx.fillRect(100,600,500,3);
ctx.stroke();
 
 
ctx.beginPath();
for(s=1;s<101;s++){
ctx.fillRect(100+5*s,600-cps[s],3,3);
}
ctx.stroke();
 
 
 
}
</script>
</head>
<body onLoad="sample()">
<canvas id="camp" width="700" height="700">
</canvas>
</body>
</html>
最終更新:2013年09月17日 19:15