Matlab: Solow Model Convergence of capital I am currently trying to create a while-loop which iterates the evolution of the capital stock until it converges on the n-th digit. As I am still quite new to Matlab I face a lot of problems. I would be very thankful for any kind of help.
Here is my code:
% Model parameters
alpha = 1/3;    %  
s     = 0.2;    % Investment rate
delta = 0.2;    % Depreciation rate
n     = 0.02;   % Growth of labor force
g     = 0.01;   % technological progress


eps  = 1;
k(1,1) = 0.5;
i=0;


while  eps &gt;= 1.0e-5        
    t = t+1;
    k(1,t) = (1/((1+n)*(1+g)))*((s*k(1,t-1)^alpha+(1-delta)*k(1,t-1)));
     z = k(1,t);       
    z1 = k(1,t+1);
         kdif = z1-z ;
          eps = max(abs(kdif));
    i = i + 1;
  if i &gt;= 300
    break;
  end
end
Since, I was urged to present an answer for didactic reasons to which I totally agree, I will provide the full set of corrections to avoid any ambiguity.
% Model parameters
alpha = 1/3;    %  
s     = 0.2;    % Investment rate
delta = 0.2;    % Depreciation rate
n     = 0.02;   % Growth of labor force
g     = 0.01;   % technological progress
eps  = 1;
k(1) = 0.5;
t=1;

while  eps &gt;= 1.0e-5        
    t = t+1;
    k(t) = (1/((1+n)*(1+g)))*((s*k(t-1)^alpha+(1-delta)*k(t-1)));
    z = k(t);         
    z1 = k(t-1);
    kdif = z-z1 ;
    eps = max(abs(kdif));
   if t &gt;= 300
     break;
   end
 end