フィルターのクリア

Nodal admittance matrix using for loop and if statement

1 回表示 (過去 30 日間)
yu yue
yu yue 2016 年 10 月 16 日
コメント済み: Andrei Bobrov 2016 年 10 月 16 日
I want to ask how can I get the matrix Y if I have the value of y1, y12, y13, y23,...,etc.
I have coding as below, but it dose not work. Who can help me?
B_matrix =[0 2.5000 0 1.6667 5.0000 0; -2.5000 0 5.0000 2.5000 0 0;0 -5.0000 0 0 5.0000 0; -1.6667 -2.5000 0 0 0 0; -5.0000 0 -5.0000 0 0 0; 0 0 0 0 0 0]
Y=zeros(6,6);
for m=1:6
for n=1:6
if m==n
for (k=1:6) & (k ~ = m)
Y(m,n)=B_matrix(m,n)+B_matrix(m,k);
else
Y(m,n)=-B_matrix(m,n);
end
end
end
end
Y

採用された回答

Andrei Bobrov
Andrei Bobrov 2016 年 10 月 16 日
Y = diag(sum(B_matrix,2)) - (~eye(size(B_matrix))).*B_matrix;
  2 件のコメント
yu yue
yu yue 2016 年 10 月 16 日
hi, it seems not right. Y(2,1)=-2.5; Y(2,2)=10; Y(3,2)=-5; Y(3,3)=10; Y(4,1) =-1.67, Y(4,2)= -2.5; Y(4,4)=4.17; Y(5,1)=-5; Y(5,3)=-5; Y(5,5)=10;
Andrei Bobrov
Andrei Bobrov 2016 年 10 月 16 日
aB = abs(B_matrix);
Y = diag(sum(aB,2)) - (~eye(size(B_matrix))).*aB;

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by