How do I create an iterated or recursive formula that includes the product of a sequence?
2 次查看(过去 30 天)
显示 更早的评论
I am new to matlab, so I apologize if my code is quite poor, but that's why I'm here!
I'm attempting to create the recursive formula below (it is formatted for LaTeX, which I don't think renders on this site, but I have attached an image of it as well):
$k_{T+1}=(1-\delta)k_T+k_{T}^\alpha-\beta^(T/\gamma)g^Tc_0\prod\limits_{t=1}^{T}R_t$\ where $R_t=\alpha k_t^{\alpha-1}+1-\delta$
The code I have attempted is below, but it is clearly incorrect as it does not like what I've tried (I have defined the variables being referred to with specific values, but I did not include those in this code sample):
t=1;
k(1)=kyratio^(1/(1-alpha));
R(1)=alpha*k(1)^(alpha-1)+1-delta
for t=2:105 j=1:105;
k(t+1)=(1-delta)*k(t)+k(t)^alpha-(beta^(1/gamma)*symprod(R(j+1),j,1,t))*czero*gstar^(-(t-1)) ;
R(j)=alpha*k(t)^(alpha-1)+1-delta ;
end
Thanks in advance for any resources you can point me towards, or any advice you give me!
2 个评论
采纳的回答
Dennie
2015-10-16
编辑:Dennie
2015-10-16
Hello,
there are a number of errors in this code, but all easy enough to fix. I can see that you tried to make 2 loops in 1, one for the k(T+1), and one for R(t). In matlab coding you can do it with just one loop since you use the same variable t. You fill the array of R with the calculation for each t and then you take the product of array R.
Also it looks to me that you define first R(t+1) before defining R(t).
Also beta^(1/gamma) should be beta^(t/gamma) judging from your formula. and gstar should be gstar^(t)
try like this:
k(1)=kyratio^(1/(1-alpha));
R(1)=alpha*k(1)^(alpha-1)+1-delta
for t=1:105
R(t)=alpha*k(t)^(alpha-1)+1-delta ;
R_prod=prod(R);
k(t+1)=(1-delta)*k(t)+k(t)^alpha-beta^(t/gamma)*czero*gstar^(t)*R_prod) ;
end
Hope this helps,
Kind regards, Dennie
更多回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!