请坛子里高手帮我看看这个MATLAB程序怎么修改,谢谢!
发布:wb123456 | 分类:Matlab软件培训
关于本站
人大经济论坛-经管之家:分享大学、考研、论文、会计、留学、数据、经济学、金融学、管理学、统计学、博弈论、统计年鉴、行业分析包括等相关资源。
经管之家是国内活跃的在线教育咨询平台!
获取电子版《CDA一级教材》
完整电子版已上线CDA网校,累计已有10万+在读~ 教材严格按考试大纲编写,适合CDA考生备考,也适合业务及数据分析岗位的从业者提升自我。
TOP热门关键词
这是程序原文:%%%%%Matlabprogram(.m)filethatgivessolutionsto"ProblemSetZero"%%%%%YoushouldplaywiththisfiletolearnsimpleMatlabcommands.%%%%%Use"help"atthecommandwindowtofigureoutwhatvariouscomm ...
免费学术公开课,扫码加入![]() |
%%%%% Matlab program (.m) file that gives solutions to "Problem Set Zero"
%%%%% You should play with this file to learn simple Matlab commands.
%%%%% Use "help" at the command window to figure out what various commands
%%%%% do. Eg, type "help clear" to figure out what the next line does.
clear all
%%%%% QUESTION 1: STEADY STATE
%%%%% Declare parameter values
g = 0.03;
n = 0.01;
s = 0.20;
alpha = 0.33;
delta = 0.04;
parameters = [g;n;s;alpha;delta];
%%%%% Declare some symbols
syms kk gg nn ss aa dd
answer = solve('(1+gg)*(1+nn)*kk-ss*kk^aa-(1-dd)*kk=0',kk);
k_bars = double(subs(answer,{gg,nn,ss,aa,dd},parameters))
% Matlab treats "symbols" differently to "numbers"; the commands above
% declare some symbols then solve the difference equation for its
% steady-state values. I then substitute the vector of parameters into the
% answer to get "numbers" back. Use the Matlab syntax "help syms", "help
% solve" etc etc to investigate this more closely.
% Keep the non-trival (positive) steady-state for future reference
k_bar= max(k_bars);
ky = k_bar^(1-alpha);
mpk = 1+alpha*k_bar^(alpha-1);
display(['Non-trivial steady state = ',num2str(k_bar)])
display(['Capital/output ratio = ',num2str(ky)])
display(['Gross marginal product of capital = ',num2str(mpk)])
%%%%% QUESTION 2: TRANSITION TO STEADY STATE
error = 10;
iter= 1;
k0 = k_bar*exp(-0.5);
% This sets the initial condition while the next command sets up an empty
% vector that we will use to store the sequence of capital stocks.
kt = [];
% The following loop iterates on the difference equation until the error is
% small (less than 10e-6)
while error > 10e-6
if iter == 1
k = k0;
else
k = kt(iter-1);
end
k1 = (s/((1+g)*(1+n)))*k^(alpha) + ((1-delta)/((1+g)*(1+n)))*k;
% The previsious line computes the subsequent capital stock k1 given
% today's capital stock k
error = abs(k1-k_bar);
kt = [kt;k1];
iter= iter+1;
end
T = length(kt);
t = [0;cumsum(ones(T-1,1))];
figure(1)
plot(t,kt,t,k_bar*ones(T,1),'k--')
title('Figure 1: Time path of the capital stock')
xlabel('time, t')
ylabel('capital stock, k(t)')
legend('k(t)',0)
%%%%% Now for the phase diagram (this is a little tricky...)
kmax = 2*k_bar;
ks = linspace(0,kmax,1000);
psis = (s/((1+g)*(1+n)))*ks.^(alpha) + ((1-delta)/((1+g)*(1+n)))*ks;
kt0 = kt(1:T-1);
kt1 = kt(2:T);
figure(2)
if k0 < k_bar
plot(kt0,kt1,'b>-',ks,ks,'k--',ks,psis,'r-')
title('Figure 2: Phase diagram')
else
plot(kt0,kt1,'b<-',ks,ks,'k--',ks,psis,'r-')
title('Figure 2: Phase diagram')
end
xlabel('k(t)')
ylabel('k(t+1)')
legend('k(t+1)','45-degree line','\psi(k(t))',0)
%%%%% PROBLEM 3: GROWTH RATE APPROXIMATIONS
%%%%% The next command produces a 1000-by-1 vector of evenly spaced "zs"
%%%%% between 0 and 1.
zs = linspace(0,1,1000)';
g_approximate = log(1+zs);
g_actuals = zs;
figure(3)
plot(100*zs,100*g_approximate,'k--',100*zs,100*g_actuals)
title('Figure 3: Accuracy of log-differences as aproximate growth rates')
xlabel('growth rate (%)')
legend('log-approximate growth rate','actual growth rate',0)
运行后显示如下错误:
??? Attempt to execute SCRIPT solve as a function.
Error in ==> D:\Matlab\toolbox\symbolic\@sym\solve.m
On line 49==> [varargout{1:max(1,nargout)}] = solve(S{:});
Error in ==> D:\Matlab\work\ps0_solutions.m
On line 25==> answer = solve('(1+gg)*(1+nn)*kk-ss*kk^aa-(1-dd)*kk=0',kk);
谢谢!!!
「经管之家」APP:经管人学习、答疑、交友,就上经管之家!
免流量费下载资料----在经管之家app可以下载论坛上的所有资源,并且不额外收取下载高峰期的论坛币。
涵盖所有经管领域的优秀内容----覆盖经济、管理、金融投资、计量统计、数据分析、国贸、财会等专业的学习宝库,各类资料应有尽有。
来自五湖四海的经管达人----已经有上千万的经管人来到这里,你可以找到任何学科方向、有共同话题的朋友。
经管之家(原人大经济论坛),跨越高校的围墙,带你走进经管知识的新世界。
扫描下方二维码下载并注册APP
免流量费下载资料----在经管之家app可以下载论坛上的所有资源,并且不额外收取下载高峰期的论坛币。
涵盖所有经管领域的优秀内容----覆盖经济、管理、金融投资、计量统计、数据分析、国贸、财会等专业的学习宝库,各类资料应有尽有。
来自五湖四海的经管达人----已经有上千万的经管人来到这里,你可以找到任何学科方向、有共同话题的朋友。
经管之家(原人大经济论坛),跨越高校的围墙,带你走进经管知识的新世界。
扫描下方二维码下载并注册APP
您可能感兴趣的文章
人气文章
本文标题:请坛子里高手帮我看看这个MATLAB程序怎么修改,谢谢!
本文链接网址:https://bbs.pinggu.org/jg/ruanjianpeixun_matlabruanjianpeixun_1078625_1.html
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。



