%adhoc2.m
%learning in an ad hoc IS-LM-PC model with feedback
lamda=0.2; %damping factor
a1=.5;
a2=1;
b1=0.1;
c1=1;
c2=0.2;
d1=0.1;
d2=-0.1;
d3=0.1;
d4=0.2;
F=eye(4);
F(1,2)=-a1; F(2,3)=b1; 
F(3,1)=-1; F(3,2)=-c1; F(3,3)=c2; F(3,4)=1;
n=ones(4,1);
G0=zeros(4);
G0(1,1)=-a2; G0(2,1)=-b1;
G1=zeros(4);
G1(1,1)=a2; G1(2,1)=b1;
L=zeros(4);
L(1,1)=1; L(4,1)=d1; L(4,2)=d2; L(4,3)=d3; L(4,4)=d4;
alpha=inv(F)*n;
gamma=inv(F)*G0;
beta=inv(F)*G1;
delta=inv(F)*L;
inia=ones(4,1);
inib=0.5*eye(4);
olda=inia; oldb=inib;
for i=1:50
	lasta=olda; lastb=oldb;
	newa=alpha+(gamma+beta+beta*oldb)*olda
	newb=beta*oldb*oldb+gamma*oldb+delta
	olda=lamda*newa+(1-lamda)*lasta;
	oldb=lamda*newb+(1-lamda)*lastb;
end;

