Use [] to index instead of ().
On Sunday, November 23, 2014 6:39:49 PM UTC-5, Pileas wrote:
>
> OK, I have the following model in which I try to solve the Bellman
> equation through function iteration. However somewhere I am wrong.
>
> This is the code:
>
> =========================================================================
>
> sigma = 1.5; # utility parameter
> delta = 0.1; # depreciation rate
> beta = 0.95; # discount factor
> alpha = 0.30; # capital elasticity of output
> nbk = 1000; # number of data points in t
> crit = 1; # convergence criterion
> epsi = 1e-6; # convergence parameter
> ks = ((1-beta*(1-delta))/(alpha*beta))^(1/(alpha-1));
> dev = 0.9; # maximal deviation from ste
> kmin = (1-dev)*ks; # lower bound on the grid
> kmax = (1+dev)*ks; # upper bound on the grid
> dk = (kmax-kmin)/(nbk-1); # implied increment
> kgrid = linspace(kmin,kmax,nbk)'; # builds the grid
> v = zeros(nbk,1); # value function
> dr = zeros(nbk,1); # decision rule (will contain indices)
>
> while crit > epsi;
> for i = 1:nbk
>
> #compute indexes for which consumption is positive
> tmp = (kgrid(i)^alpha+(1-delta)*kgrid(i)-kmin);
> imax = min(floor(tmp/dk)+1,nbk);
>
> #consumption and utility
> c = kgrid(i)^alpha+(1-delta)*kgrid(i)-kgrid(1:imax);
> util = (c.^(1-sigma)-1)/(1-sigma);
>
> # find value function
> (tv(i),dr(i)) = max(util+beta*v(1:imax));
> end;
>
> crit = max(abs(tv-v)); # Compute convergence criterion
> v = tv; # Update the value function
> end
>
> # Final solution
>
> kp = kgrid(dr);
> c = kgrid.^alpha+(1-delta)*kgrid-kp;
> util= (c.^(1-sigma)-1)/(1-sigma);
> ======================================================================
>
> It gives me the following error: ERROR: invalid assignment location
>
>
>