Adding matrices in a for loop
8 ビュー (過去 30 日間)
古いコメントを表示
I have a for loop that has # of iterations ('n'), and want to add the 1st matrix values with the 2nd matrix, then add with the 3rd matrix, till n matrix.
I initialized a matrix as zero matrix before the for loop.
I did not get the right result, could someone please fix the code?
Here is it :
ybus = zeros (busses,busses)
for i=1:lines
ybus(fbus(i),fbus(i)) = 1/(r(i)+(1i*x(i))) ;
ybus(tbus(i),tbus(i)) = ybus(fbus(i),fbus(i));
ybus(tbus(i),fbus(i)) = -1/(r(i)+(1i*x(i)));
ybus(fbus(i),tbus(i)) = -1/(r(i)+(1i*x(i))) ;
ybus=ybus+ybus
end
2 件のコメント
Geoff Hayes
2021 年 3 月 16 日
Fatima - I think we would need to more about fbus and tbus and how their values are used as indices into ybus. How are lines related to bussess? What are the dimensions of each matrix supposed to be? Is each a column array/vector or something else? Please clarify.
回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!