Summation in an element of a matrix
1 view (last 30 days)
Show older comments
Hello, i am trying to do a circiut simulator. In one part of my code i need to make a 'G' matrix each element of the Diagonal is equal to the sum of the conductance (one over the resistance) of each element connected to the corresponding node.So the first diagonal element is the sum of conductances connected to node 1, the second diagonal element is the sum of conductances connected to node 2, and so on. The off diagonal elements are the negative conductance of the element connected to the pair of corresponding node. Therefore a resistor between nodes 1 and 2 goes into the G matrix at location (1,2) and locations (2,1). I stored resistance values in a matrix like 1st coloumn is node 1 and 2nd coloumn is node 2 and 3 coloumn is value of the resistance. My problem is related with my diagonal elements. I need to sum conductances connected to corresponding node but i cant achive. Here is my code and my resistance matrix.Thanks for your help!!
G=zeros(numnodes,numnodes);
for i=1:numR
n1=Resistors(i,1);
n2=Resistors(i,2);
valueR=double(Resistors(i,3));
conductance=1/valueR;
% Checek if R is grounded or not
if n1~=0 && n2~=0
G(n1,n2)=-conductance;
G(n2,n1)=-conductance;
end
if n1~=0
G(n1,n1)=conductance;
end
if n2~=0
G(n2,n2)=conductance;
end
end
0 Comments
Answers (0)
See Also
Categories
Find more on Operating on Diagonal Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!