function foc=bca_resid(X,param);
%BCA_Resid     Residuals for the prototype business cycle model.
%

%              Ellen R. McGrattan, 11-1-05
%              Revised, ERM, 8-13-07
%______________________________________________________________________________
%
% PARAMETERS

beta       = param(1);
delta      = param(2);
eta        = param(3);
gamma      = param(4);
psi        = param(5);
sigma      = param(6);
theta      = param(7);
k0         = param(8);
T          = param(9);
inputs     = zeros(T,10);
inputs(:)  = param(10:9+10*T);
A          = inputs(:,1);
lwedge     = inputs(:,2);
xwedge     = inputs(:,3);
g          = inputs(:,4);
tauc       = inputs(:,5);
gtauh      = inputs(:,6);
gtaux      = inputs(:,7);
tauk       = inputs(:,8);
taup       = inputs(:,9);
taud       = inputs(:,10);
deriv      = param(10+10*T);
bhat       = beta*(1+gamma)^(-sigma);
thet1      = 1-theta;
delt1      = 1-delta;
grate      = (1+eta)*(1+gamma);
tauh       = 1-(1-gtauh).*lwedge;
taux       = (1+gtaux)./xwedge-1;

%______________________________________________________________________________
%
% VARIABLES APPEARING IN RESIDUALS

kn         = X(1:T);
h          = X(T+1:2*T);
k          = [k0;kn(1:T-1)];
x          = grate*kn-delt1*k;
y          = A.*k.^theta.*h.^thet1;
c          = y-x-g;
l          = 1-h;
uc         = c.^(-sigma).*l.^(psi*(1-sigma));
r          = theta*y./k;
t          = 1:T-1;
t1         = 2:T;
xtau       = (1+taux).*(1-taud)./(1+tauc);
dtau       = (1-taud).*taup./(1+tauc);
ptau       = (1-taup).*(1-taud)./(1+tauc);

foc        = [[xtau(t).*uc(t)- ...
                   bhat*uc(t1).*(ptau(t1).*(r(t1)-tauk(t1))+ ...
                           delt1*xtau(t1)+delta*dtau(t1));
                kn(T)-deriv*kn(T-1)];
              psi*(1+tauc).*c.*h./y-thet1*(1-tauh).*l]; 
