nested loop for double summation having interdependent index variables are not generating correct plots
이전 댓글 표시
I want to plot following expression of Am vs. i(index of first summation)........where Am is any quantity which is given by sum (over index i) of sum of previous Ajs and an another term ej that is again given by sum of previous eps and sum of previous Aps as follows:
Am = sum_(i=1)^(m){bi + sum_(j=0)^(i-1)[ej] + sum_(j=0)^(i-1)[Aj] }
where, ej = B + sum_(p=0)^(j-1)[ep] + sum_(p=0)^(j-1)[Ap]
I tried a nested for end loop for this and got some plot . But that plot is not showing the correct trend as it should. I am attaching my trial file
if true
% quasi_c = 0;
for var_1=1:x;
s_ep = 0;
for var_2=0:var_1-1;
s_ep = s_ep + ((1-y_c(var_2))./(1 + theta(var_2))).*(1 - (1 + theta(var_2)).*s_ep - quasi_c./kf_c(var_2));
end
quasi_c = quasi_c + kf_c(var_1).*y_c(var_1).*(1-(1+theta(var_1)).*s_ep - (quasi_c./kf_c(var_1)));
end
end
please help me in debugging it
댓글 수: 1
Jan
2013년 5월 21일
It is impossible to help you debugging, when all we know about the wnated result is, that the shown code does not create it.
답변 (1개)
Roger Stafford
2013년 5월 21일
I can't relate your matlab code to the iteration you defined for 'A' and 'e', so I can't help you with debugging. However, here is how I would carry out that iteration. I assume "bi" refers to the i-th entry to an array 'b'. If it is actually multiplication, b*i, that is easy to correct below. Also I assume 'B' is some scalar value.
A = zeros(1,m;
a = 0;
e = B;
s = 0;
for i = 1:m
s = s + a + e;
e = B + s;
a = a + b(i) + s;
A(i) = a;
end
plot(1:m,A,'yo')
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!