MATLAB Answers

Not able to use previous element in matrix inside for loop

조회 수: 1(최근 30일)
david hellenius
david hellenius 16 Feb 2020
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

로그인 to comment.

답변(1개)

Muhammad Usama Sharaf SAAFI
Declare R_p in above code. You are not showng complete code here.

  댓글 수: 0

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.


Translated by