フィルターのクリア

How to Assemble the matrix shown in the image on Matlab for any number of nodes?

6 ビュー (過去 30 日間)
amar
amar 2016 年 1 月 27 日
コメント済み: Rena Berman 2017 年 1 月 24 日

採用された回答

Walter Roberson
Walter Roberson 2016 年 1 月 30 日
n = 4; %for example
main_diagonal = [ [-4, repmat(-3,1,n-2), -4], repmat([-5, repmat(-4,1,n-2), -5], 1, 2), [-6, repmat(-5,1,n-2), -6] ];
N = length(main_diagonal);
m = diag(ones(1, N-4), -4) +
diag(ones(1, N-1), -1) +
diag(main_diagonal) +
diag(ones(1, N-1), 1) +
diag(ones(1, N-4), -4)

その他の回答 (1 件)

Guillaume
Guillaume 2016 年 1 月 27 日
There is not enough information to know how to construct the main diagonal, but you can just sum a bunch of diag:
m = diag(ones(1, 12), -4) + ...
diag(ones(1, 15), -1) + ...
diag([-4 -3 -3 -4 -5 -4 -4 -5 -5 -4 -4 -5 -6 -5 -5 -6], 0) + ... %no idea what the pattern is
diag(ones(1, 15), 1) + ...
diag(ones(1, 12), 4)
  2 件のコメント
amar
amar 2016 年 1 月 27 日
I want to assemble this matrix for any number of nodes 'n'
Walter Roberson
Walter Roberson 2016 年 1 月 27 日
main_diagonal = [-4 -3 -3 -4 -5 -4 -4 -5 -5 -4 -4 -5 -6 -5 -5 -6]; %we do not know the rule for this
n = length(main_diagonal);
m = diag(ones(1, n-4), -4) +
diag(ones(1, n-1), -1) +
diag(main_diagonal) +
diag(ones(1, n-1), 1) +
diag(ones(1, n-4), -4)

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

カテゴリ

Help Center および File ExchangeOperating on Diagonal Matrices についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by