Advertisement
Guest User

Untitled

a guest
Dec 11th, 2021
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 7.43 KB | None | 0 0
  1. % Matlab program for the deterministic continuous-time infinite-horizon Ramsey-Cass-Koopmans growth model.
  2. % Patrick Toche©  created July 2002, modified 22/04/2003
  3. % Interactive parameter selection.
  4.  
  5. function ramsey1
  6.  
  7. clear all;
  8. disp('The deterministic continuous-time infinite-horizon neoclassical growth model with CES utility and CES production. Patrick Toche©.')
  9.  
  10. global A alpha beta g d n s b p;
  11.  
  12. parameters=input('Baseline Model Parameters? Yes=1, No=0  ');
  13.  
  14. if parameters==1;
  15.      A=1;
  16.      alpha=1/3;
  17.      beta=1.5;
  18.      g=0.01;
  19.      d=0.1;
  20.      n=0;
  21.      s=1;
  22.      b=0.1;
  23.      p=0.9;
  24. else
  25.    
  26. A=input('Scale Parameter:  ');
  27. if A<0
  28.      error('Invalid Scale Parameter')
  29. end
  30.  
  31. alpha=input('Capital Income Share:  ');
  32. if alpha<0
  33.      error('Invalid Capital Income Share')
  34. end
  35. if alpha>1
  36.      error('Invalid Capital Income Share')
  37. end
  38.  
  39. warning('For an elasticity of substitution between capital and labour close to 1/2, convergence will obtain for horizons T=10 or less, while for beta close to 2, it will require T=500 or more')
  40. beta=input('Elasticity of Substitution between Capital and Labour:  ');
  41. if beta<0
  42.      error('Invalid Elasticity')
  43. end
  44.  
  45. g=input('Labour-Augmenting Growth Rate:  ');
  46. if g<0
  47.     error('Invalid Growth Rate')
  48. end
  49. if g>1
  50.     error('Invalid Growth Rate')
  51. end
  52.  
  53. d=input('Depreciation Rate:  ');
  54. if d<0
  55.     error('Invalid Depreciation Rate')
  56. end
  57. if d>1
  58.     error('Invalid Depreciation Rate')
  59. end
  60.  
  61. s=input('Elasticity of Intertemporal Substitution (1 is log):  ');
  62. if s<0
  63.     error('Invalid Elasticity')
  64. end
  65.  
  66. b=input('Discount Rate (Time Preference):  ');
  67. if b<0
  68.     error('Invalid Discount Rate')
  69. end
  70. if b>1
  71.     error('Invalid Discount Rate')
  72. end
  73.  
  74. n=input('Population Growth Rate:  ');
  75. if n<0
  76.     error('Invalid Population Growth Rate')
  77. end
  78. if n>1
  79.     error('Invalid Population Growth Rate')
  80. end
  81.  
  82. if b<n+(1-1/s)*g
  83.     error('Transversality Condition Violated')
  84. end
  85.  
  86. p=input('Percentage Deviation from Steady State (e.g. p=0.5):  ');
  87. if p<0
  88.     error('Invalid Percentage Deviation')
  89. end
  90.  
  91. end
  92.  
  93.  
  94. global T0 T N NMax RelTol AbTol;
  95.  
  96.      T0=10;
  97.      T=T0-1+input('Horizon Length:  ');
  98.      N=10;
  99.      NMax=50;
  100.      RelTol=1e-6;
  101.      AbsTol=1e-3;
  102.  
  103. global c0 css k0 kss s0 sss;
  104.      
  105. tic;
  106. fprintf('Parameters    A = %7.5f, alpha = %7.5f, beta = %7.5f, g = %7.5f, d = %7.5f, n = %7.5f, s = %7.5f, b = %7.5f\n',A,alpha,beta,g,d,n,s,b)  
  107.  
  108. %%% Compute the initial steady state
  109. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  110. kss=feval(@z,d+b+g/s); css=feval(@Y,kss)-(n+d+g)*kss;
  111. ess=[css;kss]; sss=feval(@S,css,kss);
  112. fprintf('Steady State css = %7.5f, kss =%7.5f, sss =%7.5f\n',css,kss,sss)
  113.  
  114. %%%  Computing eigenvalues
  115. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  116. odess=feval(@ODE,1,ess); %fprintf('odess = %7.5f\n',odess);
  117. jss=zeros(2,2); jss=feval(@J,1,ess); %fprintf('jss = %7.5f\n',jss);
  118. Jss=eig(jss); disp('The eigenvalues are:'); disp(Jss);
  119. tr=trace(jss); dt=det(jss); fprintf('tr = %7.9f, dt = %7.9f\n',tr,dt);
  120. if T<T0+1
  121.     error('The horizon is too short to compute the dynamics')
  122. end
  123.  
  124. %%% Define new parameters
  125. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  126. c0=css; k0=p*kss; s0=sss;
  127.  
  128. %%% Computing the dynamics
  129. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  130. guess=[c0 k0];
  131. options = bvpset('FJacobian',@J,'Vectorized','on','Stats','off','RelTol',RelTol,'AbsTol',AbsTol','NMax',NMax);
  132. solinit = bvpinit(linspace(0,T0,N),guess);
  133. sol = bvp4c(@ODE,@BC,solinit,options);
  134. t = linspace(0,T0);
  135. e = deval(sol,t);
  136. e(3,:) = feval(@S,e(1,:),e(2,:));
  137. cTss=e(1,end)/css; kTss=e(2,end)/kss;
  138. fprintf('With T = %g, c(T) = %7.5f, k(T) = %7.5f, c(T)/css = %7.5f, k(T)/kss = %7.5f\n',T0,e(1,end),e(2,end),cTss,kTss)
  139.  
  140. %%% Drawing figures
  141. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  142.  
  143. figure(1);
  144. clf;
  145. plot(t,e(1,:),'-',t(end),e(1,end),'o');
  146. title('Consumption');
  147. xlabel('t');
  148. ylabel('c(t)');
  149. hold on;
  150. drawnow;
  151.  
  152. figure(2);
  153. clf;
  154. plot(t,e(2,:),'-',t(end),e(2,end),'o');
  155. title('Capital');
  156. xlabel('t');
  157. ylabel('k(t)');
  158. hold on;
  159. drawnow;
  160.  
  161. %%% Adjusting end point and udating existing figures
  162. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  163.  
  164. for TT = T0+1:T
  165.  
  166.   solinit = bvpinit(sol,[0 TT]);
  167.   sol = bvp4c(@ODE,@BC,solinit,options);
  168.   t = linspace(0,TT);
  169.   e = deval(sol,t);
  170.   e(3,:) = feval(@S,e(1,:),e(2,:));
  171.  
  172.   cTss=e(1,end)/css; kTss=e(2,end)/kss;
  173.   fprintf('With T = %g, c(T) = %7.5f, k(T) = %7.5f, c(T)/css = %7.5f, k(T)/kss = %7.5f\n',TT,e(1,end),e(2,end),cTss,kTss)
  174.  
  175.  
  176.   figure(1);
  177.   plot(t,e(1,:),'-',t(end),e(1,end),'o');
  178.   figure(2);
  179.   plot(t,e(2,:),'-',t(end),e(2,end),'o');
  180.   drawnow;
  181.    
  182. end
  183.  
  184. hold off;
  185.  
  186. diary off;
  187.  
  188. save('ramsey.mat');
  189.  
  190.  
  191. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  192. function ode = ODE(t,e)
  193. global g d n s b;
  194. ode = [(feval(@Yk,e(2,:))-d-b-g/s).*s.*e(1,:);
  195.        feval(@Y,e(2,:))-(n+d+g).*e(2,:)-e(1,:)];
  196.    
  197. function bc = BC(e0,eT)
  198. global css kss c0 k0;
  199. bc = zeros(2,1);
  200. bc(1) = e0(2)-k0;
  201. bc(2) = eT(2)-kss;
  202.  
  203. function j = J(t,e)
  204. global g d n s b;
  205. j = zeros(2,2);
  206. j(1,1) = 0;
  207. j(1,2) = feval(@Ykk,e(2,:)).*s.*e(1,:);
  208. j(2,1) = -1;
  209. j(2,2) = feval(@Yk,e(2,:))-(n+d+g);
  210.    
  211. function rr = Y(k) %Production
  212. global A alpha beta;
  213. if beta==1
  214. rr = A*k.^(alpha);  %Cobb-Douglas Production
  215. else
  216. rr = A*(alpha*k.^((beta-1)/beta)+1-alpha).^(beta/(beta-1));  %CES Production
  217. end
  218.  
  219. function rr = Yk(k) %Marginal Product
  220. global A alpha beta;
  221. if beta==1
  222. rr = A*alpha*k.^(alpha-1);
  223. else
  224. rr = A*alpha*(alpha +(1-alpha)*k.^(-(beta-1)/beta)).^(1/(beta-1));
  225. end
  226.  
  227. function rr = Ykk(k) %Derivative of the Marginal Product
  228. global A alpha beta;
  229. if beta==1
  230. rr = A*alpha*(alpha-1)*k.^(alpha-2);
  231. else
  232. rr = A*alpha/beta*(alpha-1).*k^(-(2*beta-1)/beta)*(alpha+(1-alpha).*k^(-(beta-1)/beta))^(-(-2+beta)/(beta-1));
  233. end
  234.  
  235. function rr = z(x) %Inverse of Yk
  236. global A alpha beta;
  237. if beta==1
  238. rr = (x/A/alpha)^(1/(alpha-1));
  239. else
  240. rr = (alpha*(-(x/A/alpha)^beta*A+x)/(-1+alpha)/x)^(-beta/(beta-1));
  241. end
  242.  
  243. function rr = S(c,k) %Saving Rate
  244. rr = 1-c./feval(@Y,k);
  245.  
  246. % Matlab program for the deterministic continuous-time infinite-horizon Ramsey-Cass-Koopmans growth model.
  247. % Patrick Toche©  
  248. % Please report any problems to patrick.toche@free.fr
  249. % Program uses Matlab built-in boundary value problem routine bvp4c
  250. % Inelastic labor supply.
  251. % CES production function and CES utility function
  252. % Definition of the parameters of the model
  253. % scale production parameter                                  A
  254. % capital income share                                        alpha
  255. % elasticity of substitution capital-labour                   beta
  256. % growth of labour-augmenting technological progress          g
  257. % depreciation rate of capital                                d
  258. % growth rate of population                                   n
  259. % elaticity of intertemporal substitution in consumption      s
  260. % discount rate (rate of time preference)                     b
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement