time | Calls | line |
---|
| | 21 | function [ar_k_con,ar_l_con]=con_kl(varargin)
|
| | 22 |
|
0.001 | 1 | 23 | close all;
|
< 0.001 | 1 | 24 | bl_profile = false; % Switch off profile if running a tester/calling from another function
|
< 0.001 | 1 | 25 | if(bl_profile)
|
| | 26 | profile off;
|
| | 27 | profile on;
|
| | 28 | end
|
| | 29 |
|
0.588 | 1 | 30 | addpath(genpath('/Users/sidhantkhanna/Documents/GitHub/BKS modified/'));
|
| | 31 |
|
< 0.001 | 1 | 32 | if ~isempty(varargin)
|
| | 33 |
|
0.002 | 1 | 34 | [ar_a_v,ar_z_v,ar_a,ar_z ...
|
| 1 | 35 | fl_ahi,fl_zhi, fl_phi,fl_theta,fl_alpha,fl_w,fl_r,fl_delta,...
|
| 1 | 36 | fl_kappa,it_agridno,it_zgridno, ...
|
| 1 | 37 | ] = varargin{:};
|
| | 38 | % Display matrix and graphs of constrained k and l (for every combination of a and z)
|
| | 39 |
|
| | 40 | % if testing the index below, print out graph, and also show each
|
| | 41 | % iteration of the first order taylor approximation. if bl_state_test
|
| | 42 | % is true, then test specific state iteration to arrive at \bar{k}.
|
< 0.001 | 1 | 43 | bl_print = false;
|
< 0.001 | 1 | 44 | bl_state_test = false;
|
< 0.001 | 1 | 45 | it_test_a_idx = 1;
|
< 0.001 | 1 | 46 | it_test_z_idx = 1;
|
< 0.001 | 1 | 47 | bl_saveimg = false; % True if images are to be saved, false if you want to publish them
|
< 0.001 | 1 | 48 | it_k_n = 20000; % capital grid points to create capital grid and search for
|
| | 49 |
|
| | 50 | else
|
| | 51 |
|
| | 52 | fl_ahi = 50;
|
| | 53 | fl_zhi = 7;
|
| | 54 | it_agridno = 5;
|
| | 55 | it_zgridno = 6;
|
| | 56 | ar_a = linspace(0,fl_ahi,it_agridno); % Sample asset grid
|
| | 57 | ar_z = linspace(0.2,fl_zhi,it_zgridno); % Sample entrepreneurial productivity grid
|
| | 58 | %ar_a = 50; % for testing single a value
|
| | 59 | %ar_z = 1; % for testing single z value
|
| | 60 | [a_m,z_m] = meshgrid(ar_a,ar_z); % Meshed matrix of assets and entrepreneurial productivity
|
| | 61 | % grid (size for a_m = it_zgridnoxit_agridno, z_m =it_zgridnoxit_agridno)
|
| | 62 |
|
| | 63 | ar_a_v = a_m(:); % Meshed-vectorised asset grid
|
| | 64 | ar_z_v = z_m(:); % Meshed-vectorised entrepreneurial productivity grid
|
| | 65 | it_k_n = 20000; % capital grid points to create capital grid and search for
|
| | 66 | % constrained k
|
| | 67 | fl_phi = 0.1;
|
| | 68 |
|
| | 69 | fl_alpha = 0.4;
|
| | 70 | fl_theta = 0.79 - fl_alpha;
|
| | 71 | fl_delta = 0.06;
|
| | 72 | fl_kappa = 2;
|
| | 73 | [fl_r,fl_w,fl_ahi] = ...
|
| | 74 | deal(0.04,1.8,100);
|
| | 75 |
|
| | 76 | %% Testing Controls
|
| | 77 |
|
| | 78 | bl_print = true; % Print matrix of optimal k with graphs
|
| | 79 | bl_state_test = true; % Plotting taylor method graphs for root finding
|
| | 80 | it_test_a_idx = 2; % a index for drawing graph or root search of k using TS approx
|
| | 81 | it_test_z_idx = 4; % z index for drawing graph or root search of k using TS approx
|
| | 82 | bl_saveimg = false;
|
< 0.001 | 1 | 83 | end
|
| | 84 |
|
| | 85 | %% Parameter controls
|
< 0.001 | 1 | 86 | it_max_iter_taylor = 7; % No of iterations for taylor series approximation for constraint function
|
| | 87 |
|
| | 88 | %% Initialize Matrices
|
< 0.001 | 1 | 89 | fl_R = fl_r + fl_delta;
|
< 0.001 | 1 | 90 | mt_k_con = ones(it_agridno,it_zgridno); % Matrix for storing constrained k , for each combination on a and z
|
< 0.001 | 1 | 91 | mt_l_con = ones(it_agridno,it_zgridno);
|
| | 92 |
|
< 0.001 | 1 | 93 | fl_version = 3;
|
| | 94 | % version 1 = numerical method, version 2 = vectorised, version 3 = taylor
|
| | 95 | % series approximation for loop - has both vectorised and unvectorised
|
| | 96 | % versions
|
< 0.001 | 1 | 97 | fl_vectorised = true; % for version 3 - loop or vectorised
|
| | 98 |
|
| | 99 |
|
| | 100 | %% Version 1 - Numerical Method
|
< 0.001 | 1 | 101 | if(fl_version == 1)
|
| | 102 | for i = 1:it_agridno*it_zgridno
|
| | 103 | fl_a = ar_a_v(i);
|
| | 104 | fl_z = ar_z_v(i);
|
| | 105 | [ar_k_con(i),ar_l_con(i)] = conkl_numerical(fl_a,fl_z,fl_r,fl_w,fl_alpha,fl_theta,fl_kappa,fl_delta,fl_phi,fl_R);
|
| | 106 | end
|
| | 107 |
|
| | 108 | ar_k_con = ar_k_con'; % transposing to get same order as input vector (it_agridnoxit_zgridno x 1)
|
| | 109 | ar_l_con = ar_l_con'; % transposing to get same order as input vector (it_agridnoxit_zgridno x 1)
|
| | 110 |
|
| | 111 | mt_k_con = reshape(ar_k_con, [it_zgridno,it_agridno]);
|
| | 112 | mt_l_con = reshape(ar_l_con, [it_zgridno,it_agridno]);
|
| | 113 |
|
| | 114 | mt_k_con = mt_k_con'; % getting to matrix of dimension it_agridnoxit_zgridno
|
| | 115 | mt_l_con = mt_l_con'; % getting to matrix of dimension it_agridnoxit_zgridno
|
| | 116 |
|
| | 117 |
|
| | 118 | %% Version 2 - Vectorised solution
|
< 0.001 | 1 | 119 | elseif (fl_version == 2)
|
| | 120 |
|
| | 121 | ar_ks1 = linspace(0, 5*fl_ahi, it_k_n); % Grid of capital to search for roots of constraint equation (order = 1 X it_k_n)
|
| | 122 | ar_ks = fliplr(ar_ks1); % flipping array to pick up the second root (non-zero root)
|
| | 123 |
|
| | 124 | f_lmax = @(z,k) (fl_w./((k.^fl_alpha).*fl_theta.*z)).^(1/(fl_theta - 1)); % max l for a given constrained k
|
| | 125 |
|
| | 126 | f_con_concave = @(a,z,k) fl_phi.*((k.^fl_alpha).*z.*(f_lmax(z,k)).^fl_theta - fl_w.*(f_lmax(z,k)))-(1+fl_r)*fl_kappa.*ones(numel(a),it_k_n)+(1+fl_r).*(a).*ones(1,it_k_n);
|
| | 127 | % concave part of the constraint function
|
| | 128 |
|
| | 129 | f_con_straight = @(a,z,k) (1-fl_phi).*(1-fl_delta).*ones(numel(a),1).*k+fl_R.*ones(numel(a),1).*k;
|
| | 130 | % straight line part of the constraint function
|
| | 131 |
|
| | 132 | f_con = @(a,z,k) f_con_concave(a,z,k) - f_con_straight(a,z,k); % constraint function
|
| | 133 |
|
| | 134 | f1 = f_con(ar_a_v, ar_z_v, ar_ks);
|
| | 135 | % f1 evaulates the constraint for each combination of a,z and k. Order of f1 = ((it_agridnoxit_zgridno) X it_k_n)
|
| | 136 |
|
| | 137 |
|
| | 138 | % for i=1:it_agridno*it_zgridno
|
| | 139 | % f1(i,it_k_n)=-1000;
|
| | 140 | % end
|
| | 141 |
|
| | 142 | f1(:,it_k_n) = -1000; % assigning a large absolute value to the constraint at k=0 so as to
|
| | 143 | % remove the root k=0
|
| | 144 |
|
| | 145 |
|
| | 146 | [val, idx] = min(abs((f1)'));
|
| | 147 | % for each combi of a,z, root of the constraint equation is the k for
|
| | 148 | % which the value of the constraint function is closest to zero.
|
| | 149 | % min function on a matrix minimizes over each column, min (NXM) is of
|
| | 150 | % order (1XM). As f1 is of the order ((it_agridnoxit_zgridno) X it_k_n),
|
| | 151 | % dimension of val and idx = (1 X (it_agridnoXit_zgridno)). Since we need to minimize f1 over
|
| | 152 | % k for each combination of a and z, and dim f1=((it_agridnoxit_zgridno) X it_k_n),
|
| | 153 | % dim f1' = (it_k_n x (it_agridnoxit_zgridno)), dim min(abs((f1)'))= 1 X (it_agridnoxit_zgridno),
|
| | 154 | % dim val , idx = 1 X (it_agridnoxit_zgridno)
|
| | 155 |
|
| | 156 | [val2,idx2] = max(((f1)')); % store the max value of f1(k) for each combination of a,z
|
| | 157 | ar_k_con = ar_ks(idx); % storing constrained k values, dim = 1 X (it_agridnoxit_zgridno)
|
| | 158 |
|
| | 159 | % Analysing cases where the only root of constraint equation is k=0 in
|
| | 160 | % the range of k's we are checking
|
| | 161 | % There are 2 subcases:
|
| | 162 |
|
| | 163 | % 1) k = 0 is the only root and max of f is obtained at k = 0 ( all other
|
| | 164 | % f's are negative in the range of k's )
|
| | 165 |
|
| | 166 | % 2) k = 0 is not the only root, but only root in the given range of k's
|
| | 167 | % we are checking. The actual constrained k is very high in this case,
|
| | 168 | % so assuming the optimal would surely be less than the constrained k
|
| | 169 |
|
| | 170 | for i=1:it_agridno*it_zgridno
|
| | 171 | if (ar_k_con(i)==ar_ks1(2))
|
| | 172 | if (val2(i)<=0)
|
| | 173 | ar_k_con(i)=0; % Case 1)
|
| | 174 | else
|
| | 175 | ar_k_con(i)=1000000; % Case 2)
|
| | 176 | end
|
| | 177 | end
|
| | 178 | end
|
| | 179 |
|
| | 180 | % Limitation of this method is for case 2), if optimal k was greater than
|
| | 181 | % constrained k, those cases you are not sure about (not sure if those
|
| | 182 | % cases exist)
|
| | 183 |
|
| | 184 | ar_k_con = ar_k_con'; % transposing to get same order as input vector (it_agridnoxit_zgridno x 1)
|
| | 185 |
|
| | 186 | ar_l_con = (fl_w./(fl_theta.*ar_z_v.*ar_k_con.^(fl_alpha))).^(1/(fl_theta-1));
|
| | 187 |
|
| | 188 | mt_k_con = reshape(ar_k_con, [it_zgridno,it_agridno]);
|
| | 189 | mt_l_con = reshape(ar_l_con, [it_zgridno,it_agridno]);
|
| | 190 |
|
| | 191 | mt_k_con = mt_k_con'; % getting to matrix of dimension it_agridnoxit_zgridno
|
| | 192 | mt_l_con = mt_l_con'; % getting to matrix of dimension it_agridnoxit_zgridno
|
| | 193 |
|
| | 194 | %% Version 3 - Taylor Series Method - For loop
|
< 0.001 | 1 | 195 | elseif (fl_version == 3)
|
< 0.001 | 1 | 196 | if(~fl_vectorised)
|
| | 197 |
|
| | 198 | % Solving constraint k for each combination of a and z one by one.
|
| | 199 | % The constraint function has a linear part and a curved part.
|
| | 200 | % Starting at any point, the the curved part is approximated to a straight line with a taylor series expansion
|
| | 201 | % The intersection of the first approximation and the linear part
|
| | 202 | % is the first guess of k. At the first guess of k, approximate the
|
| | 203 | % curve part again as a stright line, then find its intersection
|
| | 204 | % with a straight line for the next guess of k. Continue doing that
|
| | 205 | % until it_max_iter_taylor iterations (you converge to the correct k in less than those no. of iterations
|
| | 206 |
|
| | 207 |
|
| | 208 | syms k w alph theta kappa r phi delta R
|
| | 209 | for i = 1:it_agridno
|
| | 210 | for j = 1:it_zgridno
|
| | 211 |
|
| | 212 | % Defining the functions using symbols only
|
| | 213 |
|
| | 214 | f_lmax = (w/((k^alph)*theta*ar_z(j)))^(1/(theta - 1)); % optimal l to constrained k
|
| | 215 | f_con_concave = phi*((k^alph)*ar_z(j)*(f_lmax)^theta - w*(f_lmax))-(1+r)*kappa+(1+r)*(ar_a(i));
|
| | 216 | % Concave part of constraint function of k
|
| | 217 | f_con_straight = (1-phi)*(1-delta)*k+R*k;
|
| | 218 | % Straight line part of constraint function of k
|
| | 219 |
|
| | 220 | % Substituting parameters in the constraint function
|
| | 221 | f_con_straight_sub = subs(f_con_straight,{w,alph,theta,kappa,r,phi,delta,R},{fl_w,fl_alpha fl_theta,fl_kappa,fl_r,fl_phi,fl_delta, fl_R});
|
| | 222 | f_con_concavej_k = subs(f_con_concave, {w,alph,theta,kappa,r,phi,delta,R}, {fl_w,fl_alpha fl_theta,fl_kappa,fl_r,fl_phi,fl_delta, fl_R});
|
| | 223 |
|
| | 224 | m = 1; % no if iteration for guess of k
|
| | 225 | kj = 1; % First guess of k
|
| | 226 |
|
| | 227 | % * a = constant term in taylor approximate of the concave part of constraint function
|
| | 228 | % * b = coefficient of k in taylor approximate of the concave part of constraint function
|
| | 229 | % * c = 0 (constant term of straight line part of constraint - staight line function chosen that way)
|
| | 230 | % * d = coefficient of k of straight line part of constraint
|
| | 231 |
|
| | 232 | if (bl_state_test)
|
| | 233 | ar_k_store = zeros(1, it_max_iter_taylor);
|
| | 234 | % Store all values of guesses of k
|
| | 235 | end
|
| | 236 |
|
| | 237 | if (fl_phi == 0) % assuming kappa = 0, id a = 0 and phi = 0, opti k = 0
|
| | 238 | mt_k_con(i,j) = ((1+fl_r)*(ar_a(i)- fl_kappa))/(1-fl_delta+fl_R);
|
| | 239 | mt_l_con(i,j) = (fl_w/((mt_k_con(i,j)^fl_alpha)*fl_theta*ar_z(j)))^(1/(fl_theta - 1));
|
| | 240 |
|
| | 241 | else
|
| | 242 | % bl_solution_exits = false;
|
| | 243 | s=0; % s increases value when a<0, case where there is no intersection of the 2 straight lines
|
| | 244 |
|
| | 245 | while (m < it_max_iter_taylor)
|
| | 246 |
|
| | 247 | f_con_concavej = double(subs(f_con_concavej_k, {k}, {kj})); % substituting first guess of k
|
| | 248 | % computing coefficients a and b of taylor series approximate
|
| | 249 | f_con_concave_diff_k = diff(f_con_concave,k);
|
| | 250 | f_con_concave_diff_kj = double(subs(f_con_concave_diff_k, {k,w,alph,theta,kappa,r,phi,delta,R}, {kj,fl_w,fl_alpha fl_theta,fl_kappa,fl_r,fl_phi,fl_delta, fl_R}));
|
| | 251 |
|
| | 252 | d = (1-fl_phi)*(1-fl_delta)+ fl_R;
|
| | 253 | a = double(f_con_concavej-f_con_concave_diff_kj*kj);
|
| | 254 | b = double(f_con_concave_diff_kj);
|
| | 255 | if (b>d) % Case where slope of tangent to curve greater
|
| | 256 | % than that of straight line), first guess needs to
|
| | 257 | % a large no.
|
| | 258 | k_jplus1=kj*100;
|
| | 259 |
|
| | 260 | elseif (a<0) % case where there is no intersection of the 2 straight lines
|
| | 261 | k_jplus1 = kj;
|
| | 262 | s=s+1;
|
| | 263 | else
|
| | 264 | k_jplus1 = (a/(d-b)); % intersection of taylor approximate and straight line part of the constraint
|
| | 265 |
|
| | 266 | end
|
| | 267 |
|
| | 268 | % Displaying coefficients of straight line and tangent to
|
| | 269 | % curved part of the constraint, and each guess of k
|
| | 270 |
|
| | 271 | if (i == it_test_a_idx && j == it_test_z_idx && bl_state_test)
|
| | 272 | st_test_iter_info_one = ['iter:', num2str(m), ', kj:', num2str(kj)];
|
| | 273 | st_test_iter_info_two = ['y-interp for lin approx of concave:', num2str(a)];
|
| | 274 | st_test_iter_info_thr = ['slope for lin approx of concave:', num2str(b)];
|
| | 275 | st_test_iter_info_fou = ['slope for origin linear line:', num2str(d)];
|
| | 276 | disp(st_test_iter_info_one);
|
| | 277 | disp(st_test_iter_info_two);
|
| | 278 | disp(st_test_iter_info_thr);
|
| | 279 | disp(st_test_iter_info_fou);
|
| | 280 | ar_k_store(m) = kj; % storing all k's which were guessed until convergence to root
|
| | 281 | end
|
| | 282 |
|
| | 283 | % updating
|
| | 284 | kj = k_jplus1; % next guess of k
|
| | 285 | m = m+1; % updating iteration for next guess of k
|
| | 286 | end
|
| | 287 |
|
| | 288 | %if(~bl_solution_exits)
|
| | 289 | % display ('constraint equation has no positive solution for capital');
|
| | 290 | %return;
|
| | 291 | %else
|
| | 292 |
|
| | 293 | mt_k_con(i,j) = kj; % updating constrained k for each a and z
|
| | 294 | mt_l_con(i,j) = (fl_w/((kj^fl_alpha)*fl_theta*ar_z(j)))^(1/(fl_theta - 1));
|
| | 295 | if (s>0)
|
| | 296 | mt_k_con(i,j)=0;
|
| | 297 | mt_l_con(i,j)=0;
|
| | 298 |
|
| | 299 | end
|
| | 300 | % updating optimal l to correponding constrained k for each a and z
|
| | 301 |
|
| | 302 | bl_state_test = true;
|
| | 303 | %% Graph Curve and line Intersection
|
| | 304 | if (i== it_test_a_idx && j == it_test_z_idx && bl_state_test)
|
| | 305 | figure(1);
|
| | 306 | hold on;
|
| | 307 | %fl_k_max = min(0.001, kj + kj/10);
|
| | 308 | fl_k_max = 120;
|
| | 309 | fplot(f_con_concavej_k, [0, fl_k_max]);
|
| | 310 | fplot(f_con_straight_sub, [0, fl_k_max]);
|
| | 311 |
|
| | 312 | for it_m = 1:1:it_max_iter_taylor
|
| | 313 | fl_kj_cur = ar_k_store(it_m);
|
| | 314 | line([real(fl_kj_cur) real(fl_kj_cur)],[0 fl_kj_cur+1], 'LineStyle', '--');
|
| | 315 | % -- lines are guesses of k
|
| | 316 | end
|
| | 317 |
|
| | 318 | line([real(kj) real(kj)],[0 kj+1]);
|
| | 319 | % final solution k
|
| | 320 | grid on;
|
| | 321 | grid minor;
|
| | 322 | if(bl_saveimg)
|
| | 323 | saveas(gcf, '/Users/sidhantkhanna/Documents/GitHub/BKS modified/code/Firms/figures/con_kl/taylor.png')
|
| | 324 | end
|
| | 325 | end
|
| | 326 | end
|
| | 327 |
|
| | 328 | end
|
| | 329 |
|
| | 330 | end
|
| | 331 |
|
| | 332 | mt_k_con1 = mt_k_con';
|
| | 333 | mt_l_con1 = mt_l_con';
|
| | 334 |
|
| | 335 | ar_k_con = mt_k_con1(:); % matrix unlayered one column under another
|
| | 336 | ar_l_con = mt_l_con1(:); % matrix unlayered one column under another
|
| | 337 |
|
| | 338 |
|
| | 339 |
|
| | 340 | %% Version 3 - Taylor Series Method - Vectorised Version
|
| | 341 |
|
< 0.001 | 1 | 342 | elseif(fl_phi==0)
|
| | 343 | ar_k_con =((1+fl_r).*(ar_a_v- fl_kappa.*ones(numel(ar_a_v),1)))./(1-fl_delta+fl_R);
|
| | 344 | ar_l_con =(fl_w./(fl_theta.*ar_z_v.*ar_k_con.^(fl_alpha))).^(1/(fl_theta-1));
|
| | 345 | ar_k_con(ar_k_con<0) = 0;
|
| | 346 | ar_l_con(ar_l_con<0) = 0;
|
| | 347 |
|
| | 348 | mt_k_con=reshape(ar_k_con, [it_zgridno,it_agridno]);
|
| | 349 | mt_l_con=reshape(ar_l_con, [it_zgridno,it_agridno]);
|
| | 350 |
|
| | 351 | mt_k_con=mt_k_con';
|
| | 352 | mt_l_con=mt_l_con';
|
| | 353 |
|
| | 354 |
|
| | 355 |
|
< 0.001 | 1 | 356 | else
|
| | 357 |
|
| | 358 |
|
< 0.001 | 1 | 359 | ar_kj = ones(it_agridno*it_zgridno, 1); % initial guess of k
|
< 0.001 | 1 | 360 | m = 1;
|
< 0.001 | 1 | 361 | s = zeros(it_agridno*it_zgridno, 1);
|
< 0.001 | 1 | 362 | s1 = zeros(it_agridno*it_zgridno, 1);
|
< 0.001 | 1 | 363 | while (m < it_max_iter_taylor)
|
< 0.001 | 6 | 364 | f_lmax = (fl_w./((ar_kj.^fl_alpha)*fl_theta.*ar_z_v)).^(1/(fl_theta - 1));
|
0.002 | 6 | 365 | f_con_concave = fl_phi*((ar_kj.^fl_alpha).*ar_z_v.*(f_lmax).^fl_theta - fl_w.*(f_lmax))-(1+fl_r)*fl_kappa.*ones(it_agridno*it_zgridno,1)+(1+fl_r).*(ar_a_v);
|
0.004 | 6 | 366 | f_con_concave_diff = fl_phi.*(fl_alpha.*ar_kj.^(fl_alpha - 1).*ar_z_v.*((fl_w./(ar_kj.^fl_alpha.*fl_theta.*ar_z_v)).^(1/(fl_theta - 1))).^fl_theta - (fl_alpha.*ar_kj.^fl_alpha.*fl_w.*((fl_w./(ar_kj.^fl_alpha.*fl_theta.*ar_z_v)).^(1/(fl_theta - 1))).^(fl_theta - 1).*(fl_w./(ar_kj.^fl_alpha.*fl_theta.*ar_z_v)).^(1/(fl_theta - 1) - 1))./(ar_kj.^(fl_alpha + 1).*(fl_theta - 1)) + (fl_alpha.*fl_w^2.*(fl_w./(ar_kj.^fl_alpha.*fl_theta.*ar_z_v)).^(1/(fl_theta - 1) - 1))./(ar_kj.^(fl_alpha + 1).*fl_theta.*ar_z_v.*(fl_theta - 1)));
|
0.001 | 6 | 367 | d = ((1-fl_phi)*(1-fl_delta)+ fl_R).*ones(it_agridno*it_zgridno, 1);
|
< 0.001 | 6 | 368 | a = (f_con_concave-f_con_concave_diff.*ar_kj);
|
< 0.001 | 6 | 369 | b = f_con_concave_diff;
|
| | 370 |
|
| | 371 | % find k_{j+1} for everyone
|
< 0.001 | 6 | 372 | ar_k_jplus1 = (a./(d-b));
|
| | 373 | % ar_k_jplus1_dup = ar_k_jplus1;
|
| | 374 |
|
| | 375 | % replace if lin approximate for slope is greater than linear slope
|
< 0.001 | 6 | 376 | ar_k_jplus1((b>d)) = ar_kj(b>d)*100;
|
| | 377 | % s1(b>d) = s1(b>d)+1;
|
< 0.001 | 6 | 378 | ar_k_jplus1((a<0) & (b<d)) = ar_kj(a<0 & b<d);
|
< 0.001 | 6 | 379 | s(a<0 & b<d) = s(a<0 & b<d)+1;
|
< 0.001 | 6 | 380 | ar_kj = ar_k_jplus1;
|
< 0.001 | 6 | 381 | m = m+1;
|
< 0.001 | 6 | 382 | end
|
| | 383 |
|
< 0.001 | 1 | 384 | ar_k_con = ar_kj;
|
< 0.001 | 1 | 385 | ar_l_con = (fl_w./(fl_theta.*ar_z_v.*ar_k_con.^(fl_alpha))).^(1/(fl_theta-1));
|
< 0.001 | 1 | 386 | ar_l_con1 = ar_l_con;
|
< 0.001 | 1 | 387 | ar_k_con(s>0) = 0;
|
< 0.001 | 1 | 388 | ar_l_con(s>0) = 0;
|
| | 389 | % ar_k_con(s1>0) = ar_kj(s1>0);
|
| | 390 | % ar_l_con(s1>0) = ar_l_con1(s1>0);
|
| | 391 |
|
< 0.001 | 1 | 392 | mt_k_con=reshape(ar_k_con, [it_zgridno,it_agridno]);
|
0.001 | 1 | 393 | mt_l_con=reshape(ar_l_con, [it_zgridno,it_agridno]);
|
| | 394 |
|
< 0.001 | 1 | 395 | mt_k_con=mt_k_con';
|
< 0.001 | 1 | 396 | mt_l_con=mt_l_con';
|
| | 397 |
|
| | 398 |
|
< 0.001 | 1 | 399 | end
|
| | 400 |
|
< 0.001 | 1 | 401 | end
|
| | 402 |
|
| | 403 |
|
| | 404 | %% Print matrix for constrained k and l
|
| | 405 |
|
< 0.001 | 1 | 406 | if(bl_print)
|
| | 407 |
|
| | 408 | disp('mt_k_con');
|
| | 409 | disp(mt_k_con);
|
| | 410 | disp('mt_l_con');
|
| | 411 | disp(mt_l_con);
|
| | 412 |
|
| | 413 | figure (2)
|
| | 414 | surf(ar_z, ar_a, mt_k_con);
|
| | 415 | title('K constraint given a and z');
|
| | 416 | xlabel('a');
|
| | 417 | ylabel('z');
|
| | 418 | zlabel('K constraint');
|
| | 419 | view(125,35);
|
| | 420 | if(bl_saveimg)
|
| | 421 | saveas(gcf, '/Users/sidhantkhanna/Documents/GitHub/BKS modified/code/Firms/figures/con_kl/Kconst_az.png')
|
| | 422 | end
|
| | 423 |
|
| | 424 | figure (3)
|
| | 425 | surf(ar_z, ar_a, mt_l_con);
|
| | 426 | title('L constraint given a and z');
|
| | 427 | xlabel('a');
|
| | 428 | ylabel('z');
|
| | 429 | zlabel('L with K constrained');
|
| | 430 | view(125,35);
|
| | 431 | if(bl_saveimg)
|
| | 432 | saveas(gcf, '/Users/sidhantkhanna/Documents/GitHub/BKS modified/code/Firms/figures/con_kl/Lconst_az.png')
|
| | 433 | end
|
| | 434 | end
|
| | 435 |
|
< 0.001 | 1 | 436 | if(bl_profile)
|
| | 437 | profile off;
|
| | 438 | profile viewer;
|
| | 439 | st_file_name = '/Users/sidhantkhanna/Documents/GitHub/BKS modified/code/Profile/Firms/con_kl';
|
| | 440 | profsave(profile('info'), st_file_name);
|
| | 441 | end
|
Other subfunctions in this file are not included in this listing.