Not able to use previous element in matrix inside for loop

2 ビュー (過去 30 日間)
david hellenius
david hellenius 2020 年 2 月 16 日
I am trying to figure out why the following simple code doesnt work:
sigma=nan(size(returns,1),1);
sigma(1)=0;
sigma(2)=0;
sigma(3)=R_p(2,1)^2;
for j=4:size(returns,1)
sigma(j)=0.94*(sigma((j-1)))^2+(1-0.94)*(R_p(j-1))^2;
end
It returns the sigma matrix with "inf" as elements. Anybody who knows why?What am i missing?
  1 件のコメント
Bhaskar R
Bhaskar R 2020 年 2 月 16 日
編集済み: Bhaskar R 2020 年 2 月 16 日
What is R_p value?

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

回答 (1 件)

Muhammad Usama Sharaf SAAFI
Muhammad Usama Sharaf SAAFI 2020 年 2 月 16 日
Declare R_p in above code. You are not showng complete code here.

カテゴリ

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