Filter löschen
Filter löschen

indexing in the nested loop

5 Ansichten (letzte 30 Tage)
Raushan
Raushan am 4 Okt. 2023
Kommentiert: Raushan am 4 Okt. 2023
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

Akzeptierte Antwort

Torsten
Torsten am 4 Okt. 2023
Bearbeitet: Torsten am 4 Okt. 2023
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 Kommentare
Torsten
Torsten am 4 Okt. 2023
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 am 4 Okt. 2023
I got you, thank you

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by