function a = galerk1(a,k0,kmax,m);
%GALERK1   Solving the nonstochastic growth model with Galerkin method.
%          a=galerk1(n,a ... )   finds the vector a describing the 
%          optimal consumption rule for:
%
%                  max int u(c)dt    s.t. dk/dt = f(k)-c, k(0) given
%                   c
%
%          The optimal rule c*=h(k) is approximated by 
%
%                  h(k)=sum a[i] phi[i][k],    k in [0,kmax]
%                        i

rho=
ks = ( (rho+delta)/(lambda*theta) )^(1/(theta-1))
k=[0:.0001:ks*2]';
l=length(k);
n=3;
basis= [ones(1,l); k; 2*k.^2-1; 4*k.^3-3*k];
basisk= [zeros(1,l); ones(1,l); 4*k; 12*k.^2-3];
r=(rho+delta-theta*lambda*k.^(theta-1))/(omega-1);

[x,w]=qgausl(0,kmax,m);

diff=1;
tol=1e-5;
while diff>tol

  h = a'*basis; 
  hk = a'*basisk;
  res = hk*(f-h)-h.*r;
  dres = basisk*(f-h)-(hk+r)*basis;
  b = w.*  ;


