You are on page 1of 2

Subroutine objct_fnct

function [f_objct] = objct_fnct(x,fpar,k,v,k0)
Z = fpar(1);
eta = fpar(2);
lambda = fpar(3);
theta = fpar(4);

lb=[eps 0];
V = [];
C = [];
H = [];
Err = [];
error = 2*tol;
cont=0;
options = optimset('Display','off','LargeScale','off');
while (error > tol) %& (cont<5)
cont = cont+1;
for i = 1:length(k_ev)
k_prev = k_ev(i);
ub = [k_ev(i) 1];
x0 = [1 0.5];
[x,value] = fmincon(fname,x0,[],[],[],[],lb,ub,[],options,fpar,k_ev,v_old,k_prev);
ktp1 = x(1);
ht = x(2);
v_new(i) = -value;
c_opt(i) = lambda*(k_prev^theta)*(ht^(1-theta)) +(1-delta)*k_prev - ktp1;
h_opt(i) = ht;
end
error = sum(abs(v_new-v_old)./max(abs(v_new),abs(v_old)))/length(k_ev)
Err(cont) = error;
v_old = v_new;
end
C = c_opt;
H = h_opt;
V = v_new;

Main Program
% Value Function and Policy Functions
clear all;
clc;
tic
tol=1e-3;
% Parameters
A = 1.72;
eta = .5;
lambda = 3;
theta = .4;
delta = .12;
beta = .98;
fpar=[A eta lambda theta delta beta];
% Possible k's
k_ev = 0:0.1:4;
k_ev(1) = eps;
np_ev = length(k_ev);
% Get the value function and policy functions

x0.(A/(1-x(2))).C. x0=[1 0.fval]=fsolve(equations.V(2:end)). kss = x(1) hss = x(2) css = lambda*(kss^theta)*(hss^(1-theta)) .fpar.H.np_ev).4) plot(k_ev.. x(1)^theta*x(2)^(1-theta) . 1/beta .1:2) plot(k_ev(2:end).v0.Err] = value_fnct('objct_fnct'.2.v0 = 85*ones(1.3) plot(k_ev. [x.H. toc % Plot results figure subplot(2.2.5].delta*x(1))^eta) .V.theta*(x(2)/x(1))^(1-theta)-(1-delta)].delta*kss .2.'r-') hold on subplot(2.[]).C. hold on subplot(2.tol).k_ev.'b-') hold off % Steady State equations = @(x) [lambda*(x(1)^theta)*(x(2)^-theta)/((lambda*. [k_ev..