Adding matrices in a for loop
8 views (last 30 days)
Show older comments
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 Comments
Geoff Hayes
on 16 Mar 2021
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.
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!