필터 지우기
필터 지우기

How do I create an iterated or recursive formula that includes the product of a sequence?

조회 수: 3 (최근 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
jlpva
jlpva 2015년 10월 16일
I want to iterate k_t about 100 times, so I wish to run this for those values of t (and j for R). Thanks!

댓글을 달려면 로그인하십시오.

채택된 답변

Dennie
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개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by