Adding matrices in a for loop
Mostrar comentarios más antiguos
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 comentarios
Geoff Hayes
el 16 de Mzo. de 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.
Fatima Yusuf
el 16 de Mzo. de 2021
Editada: Fatima Yusuf
el 16 de Mzo. de 2021
Respuestas (0)
Categorías
Más información sobre MATLAB en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!