优化目标为终生效用最大化,贝尔曼方程为V(K(t))=ln(c(t))+ln(K(t))+0.95V(K(t+1)),约束条件为:y(t)=k(t)^0.7,K(t+1)=y(t)+0.8K(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)),以此迭代贝尔曼方程直到收敛,,利用fminbnd函数求解最优的c(t),利用插值法计算各K取值的t期家庭终生效用贴现值V(K(t))的matlab代码
时间: 2023-08-09 14:10:49 浏览: 125
由贝尔曼不等式则有-常微分方程课件
以下是您所需的Matlab代码,其中包含对贝尔曼方程的迭代和对c(t)的最优化求解以及对V(K(t))的插值计算,同时考虑了终生效用最大化的优化目标:
```matlab
% 定义参数
beta = 0.95;
alpha = 0.7;
delta = 0.8;
K_min = 0.1;
K_max = 17;
c_min = 0.05;
% 定义K和c的网格
K_grid = linspace(K_min, K_max, 100);
c_grid = linspace(c_min, K_max, 100);
% 初始化V(K(t))和V(K(t+1))
V = zeros(size(K_grid));
V_new = zeros(size(K_grid));
% 迭代贝尔曼方程直到收敛
tol = 1e-6;
diff = inf;
while diff > tol
for i = 1:length(K_grid)
K = K_grid(i);
y = K^alpha;
for j = 1:length(c_grid)
c = c_grid(j);
K_next = y + (1-delta)*K - c;
if K_next < K_min || K_next > K_max
continue
end
V_temp(j) = -1*(-log(c) - log(K) + beta*interp1(K_grid, V, K_next));
end
[V_new(i), idx] = max(V_temp);
c_opt(i) = c_grid(idx);
end
diff = max(abs(V_new - V));
V = V_new;
end
% 使用fminbnd函数求解最优的c(t)
c_opt = zeros(size(K_grid));
for i = 1:length(K_grid)
f = @(c) -1*(-log(c) - log(K_grid(i)) + beta*interp1(K_grid, V, K_grid(i)^alpha + (1-delta)*K_grid(i) - c));
c_opt(i) = fminbnd(f, c_min, K_grid(i));
end
% 使用插值法计算各K取值的t期家庭终生效用贴现值V(K(t))
V_interp = interp1(K_grid, V, K_min:0.1:K_max, 'spline');
```
请注意,这只是一个简单的示例代码,实际情况可能需要更多的调整和改进。
阅读全文