%ramsey2.m
%Learning in the Ramsey model
beta=0.9;
alpha=0.3;
sigma=0.5;
kbar=((beta^(-1)-1)/alpha)^(1/(alpha-1))
cbar=kbar^alpha
ac=beta*(1+alpha*kbar^(alpha-1));
ak=-sigma^(-1)*alpha*(alpha-1)*kbar^(alpha-1);
dk=1+alpha*kbar^(alpha-1);
dc=-cbar/kbar;
a=ac;
b=dc*ak-ac*dk-1;
c=dk;
root1=(-b+(b^2-4*a*c)^0.5)/2*a;
root2=(-b-(b^2-4*a*c)^0.5)/2*a;
%root2 is the stable root
lamre=root2
phire=(lamre-dk)/dc
inilam=lamre+.02*rand(1,1);
iniphi=phire+.02*rand(1,1);
gam=.5;

phi=iniphi
lam=inilam

for i=1:100
	tphi=(ac*phi+ak)*lam;
	tlam=dk+dc*phi;
	newphi=phi+gam*(tphi-phi);
	newlam=lam+gam*(tlam-lam);
	phi=newphi
	lam=newlam
end;
	
	