global alpha % DEFINE THE GRID FOR K kmin = 1; % The minimum value for k kmax = 20; % The maximum value for k nk = 25; % 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 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 V = zeros(nk,1); % Define the matrix R KS = repmat(K',[1 nk]); KC = repmat(K',[1 nk])'; R = KS.^alpha + KS - KC; while (dd > tol) OBJ = R + beta*ones(nk,1)*V';% Define the objective function [Vnew,gi] = max(OBJ,[],2); % maximize the objective function dd = 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;