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!