フィルターのクリア

indexing in the nested loop

5 ビュー (過去 30 日間)
Raushan
Raushan 2023 年 10 月 4 日
コメント済み: Raushan 2023 年 10 月 4 日
sum_y_2_s=0;
sum_x_2_s=0;
for s=0:1:T-1
sum_y_2_s(s)=sum_y_2_s;
sum_x_2_s(s)=sum_x_2_s;
for z=s:1:T-1
sum_y_2_s(s)=sum_y_2_s(s)+y.^(z-s);
sum_x_2_s(s)=sum_x_2_s(s)+x.^(z-s);
ratio_1=(sum_y_2_s(s)./(sum_x_2_s(s)+K^(1/gamma)*x.^(T-s)));
end
if ratio_1<1
s_asterisk=s(end);
return
end
end
How should I index loop correctly. It shows
Array indices must be positive integers or logical values.
Error in opt_ret_positive_wealth (line 18)
sum_y_2_s(s)=sum_y_2_s
I am trying to find this ratio.
Thank you very much

採用された回答

Torsten
Torsten 2023 年 10 月 4 日
編集済み: Torsten 2023 年 10 月 4 日
sx = 0;
sy = 0;
for s = T-1:-1:0
sx = sx + x^(T-1-s);
sy = sy + y^(T-1-s);
ratio(s+1) = sy/(sx+K^(1/gamma)*x^(T-s));
end
  3 件のコメント
Torsten
Torsten 2023 年 10 月 4 日
The answer has changed. If x or y equal 1, you get a division by zero from the old code. The code above should cover all possible cases for x,y > 0. You should compare the results from both codes.
Raushan
Raushan 2023 年 10 月 4 日
I got you, thank you

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by