%DGCL1   Solve the deterministic growth model with a collocation method. 
%
%              Problem: Find c(k) that is optimal for 
%
%                   max  sum_t  beta^t log(c_t)
%                   c_t
%                         s.t. c_t + k_{t+1} = lambda * k_t^alpha
%
%              Solution: c(k) = (1-alpha*beta)*lambda*k^alpha
%
%              Numerical method: collocation with 
%
%                   c(k,theta)    = theta(1)*k+... theta(n)*k^n
%                   R(k(i),theta) = 0  for k(i) equally spaced
%

%        Ellen McGrattan, 8-27-96

alpha  = 1/3;
beta   =.96;
lambda = 1/(beta*alpha);
ks     = (lambda*beta*alpha)^(1/(1-alpha));
cs     = lambda*ks^alpha-ks;
n      = 5;

kgrid  = linspace(.1,2,n)';
cguess = (1-alpha*beta)*lambda*kgrid.^alpha;
K      = [];
for i=1:n;
  K      = [K,kgrid.^i];
end;
theta  = K\cguess;
param  = [alpha;beta;lambda;length(theta);kgrid];
Theta  = secant('func1',theta,param)
k      = [0:.01:1.2]';
ce     = (1-beta*alpha)*lambda*k.^alpha;
c      = zeros(length(k),1);
csa    = 0;
for i=1:length(Theta);
  c    = c+Theta(i)*k.^i;
  csa  = csa+Theta(i)*ks^i;
end;
plot(k,ce,k,c),pause
plot(k,beta*alpha*lambda*k.^alpha,k,lambda*k.^alpha-c)

