Summation in an element of a matrix
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!