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!