%TCAP_STEADY computes the steady state for the model with
%            technology capital.
%

%            Ellen McGrattan, 9-1-07
%            Revised, ERM, 1-17-08

alpha = .3;
beta  = .96;
delta = .05;
phi   = .07;
psi   = 2.;
Au    = 1;
Ar    = .365;
Zu    = Au^(1/(1-alpha*(1-phi)));
Zr    = Ar^(1/(1-alpha*(1-phi)));
Nu    = 1;
Nr    = 8;
sigu  = .75;
sigr  = .75;
lam   = 0.78989;
param = [alpha;beta;delta;lam;phi;psi;Au;Ar;Nu;Nr;sigu;sigr];
kap   = beta*alpha*(1-phi)/(1-beta*(1-delta));
mu    = beta*phi/(1-beta*(1-delta));

%
% Initial guesses:
%
Kud0  = 1.3218;
Kuf0  = 0.0474;
Krd0  = 0.0217;
Krf0  = 2.8888;
Md0   = 0.3371;
Mf0   = 0.7367;
Hud0  = .28*Nu;   
Huf0  = .01*Nu;
Hrd0  = .002*Nr;   
Hrf0  = .28*Nr;
X0    = [Kud0;Kuf0;Krd0;Krf0;Md0;Mf0;Hud0;Huf0;Hrd0;Hrf0];

%
% Solution
%
X     = secant('tcapss',X0,param);
Kud   = X(1);
Kuf   = X(2);
Krd   = X(3);
Krf   = X(4);
Md    = X(5);
Mf    = X(6);
Hud   = X(7);
Huf   = X(8);
Hrd   = X(9);
Hrf   = X(10);
Xu    = delta*(Kud+Kuf);
Xr    = delta*(Krd+Krf);
Xd    = delta*Md;
Xf    = delta*Mf;
Hu    = Hud+Huf;
Hr    = Hrd+Hrf;
Yud   = Au*(Nu*Md)^phi*(Kud^alpha*Hud^(1-alpha))^(1-phi);
Yuf   = Au*sigu*(Nu*Mf)^phi*(Kuf^alpha*Huf^(1-alpha))^(1-phi);
Yrd   = Ar*sigr*(Nr*Md)^phi*(Krd^alpha*Hrd^(1-alpha))^(1-phi);
Yrf   = Ar*(Nr*Mf)^phi*(Krf^alpha*Hrf^(1-alpha))^(1-phi);
Cu    = (Yud+Yuf+Yrd+Yrf-Xu-Xr-Xd-Xf)/(1+(1-lam)*Nr/(lam*Nu));
Cr    = (1-lam)*Cu*Nr/(lam*Nu);
Yu    = Yud+Yuf;
Yr    = Yrd+Yrf;
GDPu  = Yud+Yuf-Xd;
GDPr  = Yrd+Yrf-Xf;
NFIu  = phi*(Yrd-Yuf);
NFIr  = phi*(Yuf-Yrd);
GNPu  = GDPu+NFIu;
GNPr  = GDPr+NFIr;
NXu   = GDPu-Cu-Xu;
NXr   = GDPr-Cr-Xr;
CAu   = GNPu-Cu-Xu;
CAr   = GNPr-Cr-Xr;
Ku    = Kud+Kuf;
Kr    = Krd+Krf;
Mu    = Md+sigu^(1/phi)*Mf;
Mr    = Mf+sigr^(1/phi)*Md;
hu    = Hu/Nu;
hr    = Hr/Nr;
Du    = (1-delta*kap-delta*mu)*Yr-Cr;
Dr    = (1-delta*kap-delta*mu)*Yu-Cu;
