Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
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 commentaires
Walter Roberson
Walter Roberson le 16 Oct 2015
Please explain what you intended by
for t=2:105 j=1:105;
jlpva
jlpva le 16 Oct 2015
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!

Connectez-vous pour commenter.

Réponse acceptée

Dennie
Dennie le 16 Oct 2015
Modifié(e) : Dennie le 16 Oct 2015
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

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by