% DEFINE THE GRID FOR K kmin = 1; % The minimum value for k kmax = 20; % The maximum value for k nk = 100; % The total number of grid points kstep = (kmax - kmin)/(nk-1); %Define the step length of the grid K = kmin:kstep:kmax; % Define the grid for K % SET PARAMETERS alpha = .33; % A production function parameter beta = .95; % The Discount factor delta = .05; tol = 1e-5; % The convergence tolerance maxit = 1000; % The maximum number of iterations % SOLUTION USING FASTEST VFI SOLUTION METHOD % Initialize miss difference and iteration counter dd = 1; it = 1; % Provide initial guess for value function v1 = zeros(nk,1); v2 = zeros(nk,1); V = [v1;v2]; % Define stochastic process %%% A. z = [.5 1.5]; PI = ones(2,2)*(1/2); %%% B. % PI = [.75 .25 ; .25 .75 ]; % Define the matrix R KS = repmat(K',[1 nk]); KC = repmat(K',[1 nk])'; R1 = z(1)*KS.^alpha + KS*(1-delta) - KC; R2 = z(2)*KS.^alpha + KS*(1-delta) - KC; R = [R1;R2]; while (dd > tol) VHAT = reshape(V,nk,2); OBJ = R + beta*kron(PI,ones(nk,1))*VHAT';% Define the objective function [Vnew,gi] = max(OBJ,[],2); % maximize the objective function dd = max(max(abs(Vnew-V))); % Calculate the miss distance V = Vnew; if (it >= maxit); break; end if (max(gi) == nk) disp('Warning: Potential Corner Solution. Increase kmax'); end; if (min(gi) == 1 && it>1) disp('Warning: Potential Corner Solution. Decrease kmin'); end; it = it+1; end; gi2 = reshape(gi,nk,2);