贝尔曼方程为V(K(t))=ln(c(t))+ln(K(t))+0.95*V(K(t+1)),约束条件为:y(t)=k(t)^0.7,K(t+1)=y(t)+0.8*K(t)-c(t),设定c(t)介于0.05至K(t)之间,资本K取值0.1到17,设定t+1期各K取值的家庭终生效用贴现值V(K(t+1))初始值均为0,第t期家庭终生效用贴现值V(K(t)),并将V(K(t+1))赋值为对应K的V(K(t)),以此迭代贝尔曼方程直到收敛,利用插值法计算效用最大化条件下各K取值的t期家庭终生效用贴现值V(K(t))的matlab代码
时间: 2023-08-05 10:07:47 浏览: 113
以下是根据您提供的问题所编写的 MATLAB 代码:
```matlab
% 定义参数
beta = 0.95; % 贴现率
alpha = 0.7; % 生产函数参数
delta = 0.8; % 资本折旧率
K_min = 0.1; % 资本最小值
K_max = 17; % 资本最大值
N = 1000; % 离散化点数
tol = 1e-6; % 收敛容差
% 离散化资本K
K_grid = linspace(K_min, K_max, N)';
% 初始化价值函数V为0
V = zeros(N, 1);
% 迭代贝尔曼方程
diff = 1;
while diff > tol
V_new = zeros(N, 1);
for i = 1:N
% 计算当前资本K的最大效用值
c_min = 0.05;
c_max = K_grid(i);
c_guess = (c_min + c_max) / 2;
while abs(c_max - c_min) > 1e-6
y = K_grid(i)^alpha;
K_next = y + (1 - delta) * K_grid(i) - c_guess;
if K_next <= K_min
break;
end
V_next = interp1(K_grid, V, K_next, 'linear', 'extrap');
u = log(c_guess) + beta * V_next;
if u > log(c_guess) + beta * interp1(K_grid, V, K_min, 'linear', 'extrap')
c_max = c_guess;
else
c_min = c_guess;
end
c_guess = (c_min + c_max) / 2;
end
V_new(i) = log(c_guess) + beta * interp1(K_grid, V, K_next, 'linear', 'extrap');
end
diff = max(abs(V_new - V));
V = V_new;
end
% 绘制价值函数图像
plot(K_grid, V);
xlabel('Capital');
ylabel('Value');
title('Value Function');
% 计算最优政策函数
policy = zeros(N, 1);
for i = 1:N
c_min = 0.05;
c_max = K_grid(i);
c_guess = (c_min + c_max) / 2;
while abs(c_max - c_min) > 1e-6
y = K_grid(i)^alpha;
K_next = y + (1 - delta) * K_grid(i) - c_guess;
if K_next <= K_min
break;
end
V_next = interp1(K_grid, V, K_next, 'linear', 'extrap');
u = log(c_guess) + beta * V_next;
if u > log(c_guess) + beta * interp1(K_grid, V, K_min, 'linear', 'extrap')
c_max = c_guess;
else
c_min = c_guess;
end
c_guess = (c_min + c_max) / 2;
end
policy(i) = c_guess;
end
% 绘制政策函数图像
figure;
plot(K_grid, policy);
xlabel('Capital');
ylabel('Consumption');
title('Policy Function');
```
该代码通过离散化资本K,迭代求解贝尔曼方程,并通过插值法计算效用最大化条件下各K取值的家庭终生效用贴现值V(K(t))和最优政策函数。最终结果为价值函数和政策函数的图像。
阅读全文