宏觀經濟學

Matlab:索洛模型資本收斂

  • November 23, 2020

我目前正在嘗試創建一個 while 循環,它迭代資本存量的演變,直到它收斂到第 n 個數字。由於我對 Matlab 還是很陌生,我面臨很多問題。我會非常感謝任何形式的幫助。

這是我的程式碼:

% 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 >= 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 >= 300
   break;
 end
end

因為,我被敦促提供一個我完全同意的教學原因的答案,我將提供全套更正以避免任何歧義。

% 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 >= 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 >= 300
    break;
  end
end

引用自:https://economics.stackexchange.com/questions/41047