フィルターのクリア

nested loop shows only the result of last iteration

1 回表示 (過去 30 日間)
Raushan
Raushan 2023 年 10 月 4 日
コメント済み: Raushan 2023 年 10 月 4 日
Dear All,
T=10
for n=(0:1:(T-1))
W_t=(1+r*(1-tau)).^(-(T-n)).*C_0*epsilon.^T.*K^(1/gamma);
for m=(n+1:1:T-1)
W_t=W_t+((C_0.*epsilon.^m-L_0.*(1-tau).*g.^m).*(1+r.*(1-tau)).^(-(m-n)));
end
disp(W_t)
end
My inside loop depends on index of outside loop
This stores only W(t) at 9.
I would like to get from 0 to 9.
How can I fix this?

採用された回答

Torsten
Torsten 2023 年 10 月 4 日
...
W_t(n+1)=(1+r*(1-tau)).^(-(T-n)).*C_0*epsilon.^T.*K^(1/gamma);
for m=(n+1:1:T-1)
W_t(n+1)=W_t(n+1)+((C_0.*epsilon.^m-L_0.*(1-tau).*g.^m).*(1+r.*(1-tau)).^(-(m-n)));
end
...
  1 件のコメント
Raushan
Raushan 2023 年 10 月 4 日
Thank you very much! it worked

サインインしてコメントする。

その他の回答 (1 件)

David Hill
David Hill 2023 年 10 月 4 日
Index W_T
T=10
W_T=zeros(T,T-1);
for n=0:T-1
W_t=(1+r*(1-tau)).^(-(T-n)).*C_0*epsilon.^T.*K^(1/gamma);
for m=n+1:T-1
W_T(n+1,m)=W_t+((C_0.*epsilon.^m-L_0.*(1-tau).*g.^m).*(1+r.*(1-tau)).^(-(m-n)));
end
end
W_T
  1 件のコメント
Raushan
Raushan 2023 年 10 月 4 日
Thank you, It worked

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by