贝尔曼方程为V(K(t))=ln(c(t))+ln(K(t))+0.95*V(K(t+1)),如果K(t)>=8.6,y(t)=K(t)^0.5,如果K(t)<8.6,y(t)=K(t)^0.3,K(t+1)=y(t)+0.8*K(t)-c(t),设定c(t)介于0.05至K(t)之间,资本K的初始值K(0)=4,设定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-12 13:08:43 浏览: 81
以下是求解效用最大化条件下各K取值的t期家庭终生效用贴现值V(K(t))的MATLAB代码:
```matlab
% 设定参数
beta = 0.95;
K_min = 0.05;
K_max = 8.6;
K_grid_size = 100;
c_min = 0.05;
c_max = K_max;
c_grid_size = 100;
% 创建网格
K_grid = linspace(K_min, K_max, K_grid_size);
c_grid = linspace(c_min, c_max, c_grid_size);
% 创建初始值
V = zeros(K_grid_size, 1);
% 迭代贝尔曼方程直到收敛
tol = 1e-6;
diff = 1e10;
while diff > tol
V_new = zeros(K_grid_size, 1);
for i = 1:K_grid_size
K = K_grid(i);
if K >= 8.6
y = K^0.5;
else
y = K^0.3;
end
for j = 1:c_grid_size
c = c_grid(j);
if c > K
continue;
end
K_next = y + 0.8*K - c;
if K_next < K_min || K_next > K_max
continue;
end
V_next = interp1(K_grid, V, K_next);
if isnan(V_next)
V_next = 0;
end
u = log(c) + log(K) + beta*V_next;
if u > V_new(i)
V_new(i) = u;
end
end
end
diff = max(abs(V_new - V));
V = V_new;
end
% 绘制图像
plot(K_grid, V);
xlabel('Capital');
ylabel('Value');
title('Value Function');
```
这段代码首先设定了模型参数,并创建了资本K和消费c的网格。然后,使用初始值为0的家庭终生效用贴现值计算贝尔曼方程,直到收敛。在每个资本水平下,选择最大化效用的消费水平,并计算下一期资本的值。最后,绘制出各K取值的t期家庭终生效用贴现值V(K(t))的图像。
阅读全文