forked from Jsockin/Value_Function_Iteration_Example_Matlab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolveL1.m
More file actions
33 lines (27 loc) · 1.03 KB
/
solveL1.m
File metadata and controls
33 lines (27 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
function [l1,l2] = solveL1(alpha,delta,psi,z,A,k,kprime,l1,l1_bar)
% Setup for bisection algorithm to pin down l1 given l2
lowerL1 = 0;
upperL1 = l1_bar;
difference = 1;
epsilon = 10^-6;
imagThreshold = 10^-4;
% Solve for optimal l1 given l1 using bisection
while abs(difference) > epsilon
c1 = exp(z)*k^alpha*l1^(1-alpha) + (1-delta)*k - kprime;
l2 = ((1-psi) * c1) / (psi * (1-alpha) * exp(z) * (k/l1)^alpha);
lhs = (l1 + l2)^(1/psi) * l1^alpha;
rhs = psi * (A*(1-psi))^((1-psi)/psi) * (1-alpha) * exp(z) * k^alpha;
difference = lhs - rhs;
% Value for l1 from bisection leads to negative consumption
if abs(imag(difference)) > imagThreshold
l1 = -1;
break;
elseif difference > 0
upperL1 = l1;
l1 = l1 - 0.5 * (l1 - lowerL1);
elseif difference < 0
lowerL1 = l1;
l1 = l1 + 0.5 * (upperL1 - l1);
end
end
end