- Check your model equations: Make sure that your model equations are correct and that you're using the right parameter values. If your model equations are incorrect, then your optimization algorithm won't be able to find the right solution.
- Check convergence criteria: Make sure that your convergence criteria are appropriate for your problem. If your criteria are too strict, then your algorithm may never converge. If they're too loose, then your algorithm may converge to a suboptimal solution.
Shooting Algorithm - Neoclassical growth model
31 次查看(过去 30 天)
显示 更早的评论
I have encountered problems when trying to find steady stater for neoclassical growth model.
Code stucks in the model and does nothing. Also, I am trying to find some particular initial consumption that will lead me to steady state and for that I am using while loop, but I am not sure if this while loop works or not becase it does not change the value of initial consumption when particular condition is not met. Moreover, it draws some ridiculous figures
Could you please look at the code and tell me what I am doing wrong.
flag_update_c0 = 1;
% I am trying to find optimal c0.
% In this while loop I am trying to write it in a way that gets me to
% particular c0, which in turn, then will lead me to steady state
while flag_update_c0==1
% updates c0
c0=(c0_lb+c0_ub)/2;
k_old = k0;
c_old = c0;
flag_simulate_paths = 1;
while flag_simulate_paths==1
%I am generating new values k and c untill I reach some point where
%new k and new c will be the closest to their steady state values.
k_dot = k_old^alpha-c_old+(1-delta)*k_old;
c_dot = c0*(beta*(alpha*k_old^(alpha-1) +1- delta))^(1/sigma);
k_new = k_old + Delta * k_dot;
c_new = c_old + Delta * c_dot;
% 4 things can happen:
%if k and c are close to their steady state values, then I am sayng
%that stop updating c0. I found the right c0 (initial c)
if abs((k_new - k_ss)) < tol && abs((c_new - c_ss)) < tol
% we're close to the steady state
flag_simulate_paths = 0;
flag_update_c0 = 0;
% considering that I am trying to find steady state, I do not want
% consumption decrease, so if consumption starts to decrease, I am trying
% to say that keep stop simulating path and keep update c0,
elseif c_new < c_old
% consumption starts to decrease
flag_update_c0=1;
c0=(c0_lb+c0_ub)/2;
% same goes here, I do not want to capital to start decrease so
% keep update c0.
elseif k_new < k_old
% capital starts to decrease
flag_update_c0=1;
c0=(c0_lb+c0_ub)/2;
else
% none of the above
k_old = k_new;
c_old = c_new;
end
end
end
Thank you in advance
0 个评论
回答(1 个)
Yash
2023-11-21
Hello Mari,
I understand that the code you provided is attempting to find the optimal initial consumption value for a neoclassical growth model, but is encountering some issues. Here are a few suggestions:
Here's an example code to find a particular initial consumption value that will lead to the steady state for a neoclassical growth model:
% Define the model parameters
alpha = 0.3; % capital share of output
beta = 0.95; % discount factor
delta = 0.1; % depreciation rate
sigma = 2; % intertemporal elasticity of substitution
% Define the steady-state values
k_ss = (alpha / (1/beta - (1-delta)))^(1/(1-alpha));
c_ss = (1-alpha)*k_ss^alpha;
% Define the tolerance level
tol = 1e-6;
% Define the lower and upper bounds for initial consumption
c0_lb = 0;
c0_ub = c_ss;
% Define the initial consumption value
c0 = c_ss/2;
% Define the time step and simulation horizon
Delta = 0.01;
T = 100;
% Simulate the model dynamics
for t = 1:T
% Compute the new values of k and c
k_dot = k_ss^alpha - c0 + (1-delta)*k_ss;
c_dot = c0*(beta*(alpha*k_ss^(alpha-1) + 1 - delta))^(1/sigma);
k_ss_new = k_ss + Delta*k_dot;
c_ss_new = c0 + Delta*c_dot;
% Check if we've reached the steady state
if abs(k_ss_new - k_ss) < tol && abs(c_ss_new - c_ss) < tol
break;
end
% Update the values of k and c
k_ss = k_ss_new;
c_ss = c_ss_new;
end
% Print the results
fprintf('Initial consumption value: %f', c0);
fprintf('Steady-state capital stock: %f', k_ss);
fprintf('Steady-state consumption: %f', c_ss);
In this example, we first define the model parameters and the steady-state values of capital and consumption. We then define the tolerance level, lower and upper bounds for initial consumption, and the initial consumption value. We simulate the model dynamics using a for loop and check if we've reached the steady state at each time step. Finally, we print the results.
Hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!