function res = res_rbc(Z,param);
%RES_RBC    First order conditions of RBC model.
%

%           Ellen R. McGrattan, 7-3-10
%           Revised, ERM, 12-5-13

%______________________________________________________________________________
%
% PARAMETERS

alpha      = param(1);
beta       = param(2);
delta      = param(3);
gn         = param(4);
gz         = param(5);
psi        = param(6);
theta      = param(7);
betg       = beta*(1+gz)^(-alpha);
thet1      = 1-theta;

%______________________________________________________________________________
%
% VARIABLES APPEARING IN RESIDUALS



k          = exp(Z(1));
k1         = exp(Z(2));
k2         = exp(Z(3));
z          = exp(Z(4));
tauc       = Z(5);
taud       = Z(6);
tauh       = Z(7);
tauk       = Z(8);
taup       = Z(9);
taux       = Z(10);
g          = exp(Z(11));
z1         = exp(Z(12));
tauc1      = Z(13);
taud1      = Z(14);
tauh1      = Z(15);
tauk1      = Z(16);
taup1      = Z(17);
taux1      = Z(18);
g1         = exp(Z(19));
c          = exp(Z(20));
c1         = exp(Z(21));
h          = exp(Z(22));
h1         = exp(Z(23));
uc         = c^(-alpha)*(1-h)^(psi*(1-alpha));
uc1        = c1^(-alpha)*(1-h1)^(psi*(1-alpha));
r1         = theta*(z1*h1/k1)^thet1;

res        = [c+(1+gz)*(1+gn)*k1+g-(1-delta)*k-k^theta*(z*h)^thet1;
              c1+(1+gz)*(1+gn)*k2+g1-(1-delta)*k1-k1^theta*(z1*h1)^thet1;
              (1+tauc)*psi*c*h^theta/(k^theta*z^thet1*thet1*(1-tauh))-1+h;
              (1+tauc1)*psi*c1*h1^theta/(k1^theta*z1^thet1*thet1*(1-tauh1))-1+h1;
              (1-taud)*(1+taux)-betg*(1-taud1)*(1+tauc)*uc1* ...
                 (1+(1-taup1)*(r1-delta-tauk1)+(1-delta)*taux1)/(uc*(1+tauc1))];

