%  muth2sys.m

% ***********************************************************************
% The model is written as:
%
% A*y(t+1/t) = B*y(t) + C(F)*x(t/t),
%
% where C(F) = C0 + C1*F + C2*F^2 + ... + CN*F^N, where F is defined as the
% forward shift operator; i.e., F*x(k/t) = x(k+1/t).
%
% Output parameters:
% A
% B
% C = [C0, C1,..., CN]
% LPD = Array that contains locations of predetermined variables in the
%       y vector.
%
% YLIST = Array of names of the elements of y (strings)
% XLIST = Array of names of the elements of x (strings)
% ny: Number of elements of y
% nx: Number of elements of x
% nlead: Number of leads of x(t+j/t) -- (i.e., n in the above equation).
% np: number of predetermined variables


% **********************
% LISTS OF VARIABLES
% AND ASSOCIATED INDICES
% **********************

vlstmuth2
load imuth2


% ****************
% system dimension
% ****************

ny=rows(ylist);
nx=rows(xlist);
nlead=1;

lpd=[ik];

% ********************************* %
% DEFINING THE MATRICES A, B AND C  %
% ********************************* %
%
% -----------------------------------------------
% Equations are written in the form
% A*Ey(t+1)|I(t) = B*Ey(t)|I(t) + C(F)*Ex(t)|I(t)
% where C(F) = C0 + C1F + ... + CnF^n
% -----------------------------------------------

% Initialize Matrices:

A=zeros(ny,ny);
B=zeros(ny,ny);

% One lead max

CF=zeros(ny,2*nx);
elist=[];
eqn=0;

% Model parameters

sigma=.1;
alpha=.2;
theta=4;
b=.99;

% EQN1

[elist,eqn]=ADDEQN('supply',elist,eqn);

B(eqn,iq)=-1;
B(eqn,ip)=sigma;
B(eqn,ik)=1;

% EQN2

[elist,eqn]=ADDEQN('demand',elist,eqn);

B(eqn,iq)=1;
B(eqn,ip)=alpha;
A(eqn,ik)=1;
CF(eqn,ix)=-1;

% EQN3

% Mistake 1: Equation not added (EQ (2) overwritten)
% to correct this error remove the '%' sign in the next line
% [elist,eqn]=ADDEQN('inventory',elist,eqn);

A(eqn,ik)=1;

% Mistake 2: negative sign omitted: correct equations reads
%
% A(eqn,ip)=-b*theta;
% B(eqn,ip)=-theta;
A(eqn,ip)=b*theta;
B(eqn,ip)=theta;
Undefined command/function 'MAKEID'.