% ch4_2.m
% Sargent-Wallace model
%Figure 4.2
randn('seed',15);
alpha=1;
ap=1; br=-.2; cq=1; cr=-.5;
beta0=(ap*(1+br*cq/cr)+br)/(ap*(1+br*cq/cr)+br/cr);
beta1=(1-beta0)/(1-cr^(-1));
tmax=600;
sig=0.5;
a=zeros(tmax,1);
p=zeros(tmax,1);
anaught=4;
p(1)=alpha+(beta0+beta1)*anaught+sig*randn(1);
a(1)=p(1);
for t=2:tmax
p(t)=alpha+(beta0+beta1)*a(t-1)+sig*randn(1);
a(t)=a(t-1)+t^(-1)*(p(t)-a(t-1));
end
figure(1)
subplot(2,1,1)
plot(a) 
title('Figure 4.2')
xlabel('time')
ylabel('a(t)')
subplot(2,1,2)
plot(p) 
xlabel('time')
ylabel('p(t)')
